Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TableRow垂直拉伸以填充屏幕_Android - Fatal编程技术网

Android TableRow垂直拉伸以填充屏幕

Android TableRow垂直拉伸以填充屏幕,android,Android,我正在尝试创建一个电话拨号器视图,使用一个表布局在一个3x4网格中创建12个按钮。我希望行垂直拉伸以平均使用所有可用空间,但填充父行似乎不适用于TableRows 我不想使用setMinimumHeight-有没有办法在布局中正确地使用它 非常感谢 Ed 我本来打算发布一个包含两个嵌套线性布局中的按钮的解决方案,但您的解决方案似乎也可以正常工作,并且按照OP的要求使用了表格布局。:)很酷,但是如何在java代码中实现呢?我尝试在运行时只知道行数和列数的情况下得到类似的结果,但在android.

我正在尝试创建一个电话拨号器视图,使用一个表布局在一个3x4网格中创建12个按钮。我希望行垂直拉伸以平均使用所有可用空间,但填充父行似乎不适用于TableRows

我不想使用setMinimumHeight-有没有办法在布局中正确地使用它

非常感谢

Ed



我本来打算发布一个包含两个嵌套线性布局中的按钮的解决方案,但您的解决方案似乎也可以正常工作,并且按照OP的要求使用了表格布局。:)很酷,但是如何在java代码中实现呢?我尝试在运行时只知道行数和列数的情况下得到类似的结果,但在
android.widget.TableLayout.mutateClumnswidth(TableLayout.java:579)
中得到
java.lang.arithmetricException:除零。真不敢相信Android布局系统真的这么迟钝。谢谢,使用Android:stretchColumns=“*”这是一个很好的答案,我唯一注意到的是,
LinearLayout
是多余的。非常感谢这个答案。你能解释一下是否真的需要线性布局吗?谢谢
<?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>