在Android中的表格布局中设置相等的列宽

时间:2011-07-11 07:49:52

标签: android tablelayout

  

可能重复:
  XML Table layout? Two EQUAL-width rows filled with equally width buttons?

我正在使用TableLayout来显示4列中的数据列表。

问题描述:

我无法设置所有4列的相等宽度,这些列位于我的TableLayout中。 我正在使用我正在使用的布局代码......

<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="0">
        <TableRow>
            <TextView android:text="table header1" android:layout_width="wrap_content" android:layout_height="wrap_content" 
                 android:textSize="10dip" android:textStyle="bold"/>    
            <TextView android:text="table header2" android:layout_width="wrap_content" android:layout_height="wrap_content" 
                android:textSize="10dip" android:textStyle="bold"/> 
            <TextView android:text="table header3" android:layout_width="wrap_content" android:layout_height="wrap_content" 
                android:textSize="10dip" android:textStyle="bold"/> 
            <TextView android:text="table header4" android:layout_width="wrap_content" android:layout_height="wrap_content" 
                android:textSize="10dip" android:textStyle="bold"/>         
        </TableRow>
    </TableLayout>

我应该如何重写此布局以显示大小相等的4列?

2 个答案:

答案 0 :(得分:178)

Try this.

归结为将android:stretchColumns="*"添加到TableLayout根并将android:layout_width="0dp"设置为TableRow中的所有子项。

<TableLayout
    android:stretchColumns="*"   // Optionally use numbered list "0,1,2,3,..."
>
    <TableRow
        android:layout_width="0dp"
    >

答案 1 :(得分:67)

android:stretchColumns值更改为*

0表示拉伸第一列。值1表示拉伸第二列,依此类推。

*表示拉伸所有列。

相关问题