Android TableRow垂直拉伸以填充屏幕 [英] Android TableRow stretch vertically to fill screen
本文介绍了Android TableRow垂直拉伸以填充屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用TableLayout在3x4网格中创建12个按钮来创建电话拨号程序视图.我希望这些行垂直伸展以均等地占用所有可用空间,但似乎fill_parent在TableRows上不起作用.
I'm trying to create a phone dialer view, using a TableLayout to create the 12 buttons in a 3x4 grid. I would like the rows to stretch vertically to use up all available space equally, but it appears fill_parent doesn't work on TableRows.
我不想不必使用setMinimumHeight-有没有办法在布局中正确地做到这一点?
I would like not to have to use setMinimumHeight - is there a way to do this properly in the layout?
非常感谢
Ed
推荐答案
<?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垂直拉伸以填充屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文