如何使表格布局中的列均匀分布,最大限度地利用可用空间

Ami*_*mit 15 android android-widget

我只是尝试使用表格布局来显示一些数据....数据是一个3列数据,我希望列应该利用可用的整个宽度.但似乎我使用的布局XML代码只是根据内容包装列.

布局XML代码

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >   
    <TableRow
        android:layout_width="fill_parent">
        <TextView
            android:padding="3dip"
            android:gravity="left"
            android:text="Name"
            />
        <TextView
            android:padding="3dip"
            android:gravity="left"
            android:text="Address"
            />

        <TextView
            android:padding="3dip"
            android:gravity="left"
            android:text="Age"
            />  
    </TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)

Com*_*are 31

您可以尝试添加android:stretchColumns="0,1,2"到您的<TableLayout>元素.

  • `android:stretchColumns ="*"` - 这将导致默认情况下拉伸所有列. (20认同)