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

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

该怎么做呢?
它应该看起来像第一张图片。
发布于 2013-04-11 11:06:52
可能有更好的方法可以做到这一点,实际上我以前没有使用过TableLayout,但是下面的XML给出了您所要求的基本布局:
<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>发布于 2013-04-11 22:37:08
Yojimbo,你是对的,但是如果你使用
android:layout_weight
您必须记住将android:layout_width="wrap_content“(在这种特殊情况下)替换为
android:layout_width="0dp“。
Here你有一个很好的推荐人。
https://stackoverflow.com/questions/15939292
复制相似问题