二者都
TableLayout
和
TableRow
是
LinearLayouts
。所以使用
weight
属性将提供所需的结果:
-
设置
TableLayout's
宽度和高度
match_parent
-
设置
layout_height="0dp"
和
layout_weight="0.5"
对于
TableRows
使它们分别适合屏幕高度的50%;
-
设置每个
Button's
高度到
匹配_租金
填充行的高度,并设置
layout_width="0dp"
和
layout_weight=“0.5”
以使行的宽度相等。
布局如下:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="New Button"
android:id="@+id/button1" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="New Button"
android:id="@+id/button4" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="New Button"
android:id="@+id/button2" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="New Button"
android:id="@+id/button3" />
</TableRow>
</TableLayout>
下面是它的样子: