使细胞相同的宽度和高度,以填补该表 [英] Make cells same width and height to fill the table
问题描述
我想学习如何使用表格布局在Android中,这是我的code:
I'm trying to learn how to use table layouts in android, this is my code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- 3 columns -->
<TableRow
android:id="@+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip" >
<TextView
android:id="@+id/textView2"
android:text="Column 1" />
<Button
android:id="@+id/button2"
android:text="Column 2" />
<Button
android:id="@+id/button3"
android:text="Column 3" />
</TableRow>
</TableLayout>
这是结果:
我怎样才能让的TableRow
以适合的宽度 TableLayout
和高度的 TableLayout
的高度?在简单的话,我想有相同的宽度和行的所有列具有相同的高度填充 TableLayout
,这可能吗?怎么样?
How can I make the TableRow
to fit the width of the TableLayout
and the height to the TableLayout
height? In simple words, I would like to have all columns with the same width and rows with the same height filling the TableLayout
, is it possible? How?
推荐答案
您需要用重量
价值的发挥。在XML的两排是这样的。 -
You need to play with weight
values. The xml for two rows would look like this.-
<?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" >
<!-- 3 columns -->
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dip" >
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Column 1" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Column 2" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Column 3" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dip" >
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Column 1" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Column 2" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Column 3" />
</TableRow>
</TableLayout>
这是结果。 -
And this is the result.-
作为一个侧面说明,注意 FILL_PARENT
是德precated,你应该使用 match_parent
代替。
As a side note, notice that fill_parent
is deprecated, you should use match_parent
instead.
这篇关于使细胞相同的宽度和高度,以填补该表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!