首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android中的表格布局(span/shrink)?

android中的表格布局(span/shrink)?
EN

Stack Overflow用户
提问于 2013-04-11 09:28:02
回答 2查看 1.6K关注 0票数 0

我想要这个特殊的表格布局:

在我当前的布局中,较短的单元格的大小与具有长文本的单元格相同:

该怎么做呢?

它应该看起来像第一张图片。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-11 11:06:52

可能有更好的方法可以做到这一点,实际上我以前没有使用过TableLayout,但是下面的XML给出了您所要求的基本布局:

代码语言:javascript
复制
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="4"
                android:layout_weight="1"
                android:text="Text"
                android:gravity="center" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:text="Text" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:layout_weight="0.75"
                android:text="Text that is longer than other cells" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:text="Text" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:text="Text" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:text="Text" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:text="Text" />
        </TableRow>
    </TableLayout>
票数 2
EN

Stack Overflow用户

发布于 2013-04-11 22:37:08

Yojimbo,你是对的,但是如果你使用

android:layout_weight

您必须记住将android:layout_width="wrap_content“(在这种特殊情况下)替换为

android:layout_width="0dp“。

Here你有一个很好的推荐人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15939292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档