使用TableLayout和TableRow的间距问题

时间:2013-08-12 18:10:35

标签: android android-layout android-tablelayout

我在XML文件中进行了以下设置:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/table_more_features"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_blue" >
    ...
<TableRow
        android:id="@+id/tableRow7"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/cell_top"
        android:padding="5dip" >

        <TextView
            android:id="@+id/txt_foo"
            android:background="@android:color/transparent"
            android:layout_weight=".3"
            android:text="Foo" />

        <TextView
            android:id="@+id/txt_bar"
            android:background="@android:color/transparent"
            android:layout_weight=".3"
            android:text="Bar" />

        <TextView
            android:id="@+id/txt_woo"
            android:background="@android:color/transparent"
            android:layout_weight=".3"
            android:text="Woo" />
    </TableRow>
...
</TableLayout>

结果类似于this

似乎无论我尝试什么,我都无法在三个TextView之间获得均匀的间距,第一个总是占据房间的大部分。我试图将所有3个均匀地水平分布。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

虽然在我的AS中,您的代码可以均匀分配,但您可以尝试以下方法:

  • 到每个TextView添加android:layout_width="0dp"
  • (可选)到表格行添加android:weightSum="1"