【问题标题】:Issue with spacing using TableLayout and TableRow使用 TableLayout 和 TableRow 的间距问题
【发布时间】:2013-08-13 02:25:48
【问题描述】:

我在一个 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>

结果看起来像

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

感谢您的帮助。

【问题讨论】:

    标签: android android-layout android-tablelayout


    【解决方案1】:

    虽然在我的 AS 中您的代码空间均匀,但您可以尝试以下操作:

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

    【讨论】:

      猜你喜欢
      • 2011-02-10
      • 2012-03-26
      • 1970-01-01
      • 2022-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      相关资源
      最近更新 更多