【问题标题】:Stretch one column, shrink others in Android TableLayot在 Android TableLayot 中拉伸一列,缩小其他列
【发布时间】:2014-08-29 12:04:00
【问题描述】:

我想在下面拉伸pool_team 列并让其他列缩小到列宽。不过,我似乎无法正确处理。其他列将包含一个小整数,pool_team 将包含一个可以换行的长名称。

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pool_table"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"
    android:shrinkColumns="0">

    <TableRow
        android:id="@+id/pool_row"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center">

        <TextView
            android:id="@+id/pool_number"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_weight="1"
            android:textAlignment="center" />

        <TextView
            android:id="@+id/pool_team"
            android:layout_width="0dip"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/pool_wins"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_weight="1"
            android:textAlignment="center" />

        <TextView
            android:id="@+id/pool_loses"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_weight="1"
            android:textAlignment="center" />

        <TextView
            android:id="@+id/pool_point_difference"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_weight="1"
            android:textAlignment="center" />

        <TextView
            android:id="@+id/pool_place"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_weight="1"
            android:textAlignment="center" />
    </TableRow>

</TableLayout>

【问题讨论】:

  • 你能发布一张图片,它的样子和你想要的样子吗?

标签: android tablelayout android-tablelayout


【解决方案1】:

这样的?

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pool_table"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TableRow
    android:id="@+id/pool_row"
    android:weightSum="1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center" >

    <TextView
        android:id="@+id/pool_number"
        android:layout_width="0dp"
        android:layout_weight=".1"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="123" />

    <TextView
        android:id="@+id/pool_team"
        android:layout_width="0dp"
        android:layout_weight=".5"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Some longer text that may or may not wrap around to the next line...." />

    <TextView
        android:id="@+id/pool_wins"
        android:layout_weight=".1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="123" />

    <TextView
        android:id="@+id/pool_loses"
        android:layout_weight=".1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="123" />

    <TextView
        android:id="@+id/pool_point_difference"
        android:layout_width="0dp"
        android:layout_weight=".1"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="123" />

    <TextView
        android:id="@+id/pool_place"
        android:layout_weight=".1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="123" />
</TableRow>

【讨论】:

    最近更新 更多