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

2023-09-12 07:06:16 作者:我猜你在偷看我

可能重复:   XML表格布局?两个等宽行充满了同样的宽度按钮?

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

I am using TableLayout to show list of data in 4 columns.

问题描述:的

Problem description:

我无法将所有4列,这是在我的 TableLayout 的宽度相等。 我把我的布局code,我现在用的...

I am unable to set equal width of all 4 columns, which are in my TableLayout. I am putting my layout code, which I am using...

<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柱大小相等?的

推荐答案

使用这种方式: http://androidadvice.blogspot.com/2010/10/tablelayout-columns-equal-width.html

它归结为加入安卓stretchColumns =1 TableLayout 根和设置机器人:layout_width =0dp在所有孩子的的TableRow的

It boils down to adding android:stretchColumns="1" to your TableLayout root and setting android:layout_width="0dp" to all the children in your TableRow's