我正在尝试创建一个电话拨号器 View ,使用 TableLayout 在 3x4 网格中创建 12 个按钮。我希望行垂直拉伸(stretch)以平均使用所有可用空间,但似乎 fill_parent 不适用于 TableRows。
我不想使用 setMinimumHeight - 有没有办法在布局中正确执行此操作?
非常感谢,
埃德
最佳答案
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*"
>
<TableRow
android:layout_weight="1"
android:gravity="center">
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="center">
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="center">
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="center">
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
<Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
</TableRow>
</TableLayout>
</LinearLayout>
关于Android TableRow 垂直拉伸(stretch)以填满屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5538366/