我正在尝试创建一个包含 2x2 按钮网格(总共 4 个)的布局。我有以下内容,但它只在左上角创建按钮网格。我希望按钮网格填满整个屏幕。
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="@+id/button4"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableRow>
试试这个代码。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
</TableRow>
</TableLayout>
你应该使用按钮的重量
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)