2

我正在开发一个 Android 应用程序。

我有这个布局:

在此处输入图像描述

我不想让 textview 填满一整列。正如您在上一张图片中看到的那样,有一个被蓝色矩形包围的 TextView(实际上已被选中)。这是创建该 TableRow 的 XML 代码:

<TableRow>

    <TextView
        android:id="@+id/txtFactLoc"
        android:layout_span="2"
        android:gravity="center_vertical|right"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="@string/layout_fac_location"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/factLocVal"
        android:layout_span="4"
        android:gravity="center_vertical"
        android:paddingLeft="10dp"
        android:layout_height="match_parent"
        android:background="@color/textview_background"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/txtConFactLoc"
        android:gravity="center_vertical"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="@string/layout_confirm"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <RadioGroup
        android:id="@+id/rGroupFactLoc"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/rFactLocYes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/layout_yes" />

        <RadioButton
            android:id="@+id/rFactLocNo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/layout_no" />

    </RadioGroup>

</TableRow>

位于具有八列的 TableLayout 内。这是 TableLayout 的开始:

<TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_margin="10dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:shrinkColumns="*"  
        android:stretchColumns="*">

        <TableRow>
        <TextView
            android:id="@+id/txtPONo"
            android:layout_weight=".125"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="@string/layout_po_no"
            android:textAppearance="?android:attr/textAppearanceMedium" />


        <TextView
            android:id="@+id/pONoVal"
            android:layout_weight=".125"
            android:layout_width="0dip"
            android:paddingLeft="10dp"
            android:layout_height="match_parent"
            android:background="@color/textview_background"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/txtIndNo"
            android:layout_weight=".125"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="@string/layout_ind_no"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/indNoVal"
            android:layout_weight=".125"
            android:layout_width="0dip"
            android:paddingLeft="10dp"
            android:layout_height="match_parent"
            android:background="@color/textview_background"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/txtTimeIn"
            android:layout_weight=".1"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="@string/layout_time_in"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/timeInVal"
            android:layout_weight=".15"
            android:layout_width="0dip"
            android:paddingLeft="10dp"
            android:layout_height="match_parent"
            android:background="@color/textview_background"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/txtTimeOut"
            android:layout_weight=".1"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="@string/layout_time_out"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/timeOutVal"
            android:layout_weight=".15"
            android:layout_width="0dip"
            android:paddingLeft="10dp"
            android:layout_height="match_parent"
            android:background="@color/textview_background"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </TableRow>

一些 textViews 有背景颜色。正如你所看到的,它们都填满了它的列,我不希望这样,因为这个表单看起来很丑。

如何更改 TextView 的宽度?如果我设置了 android:layout_span="2" 我不能改变它的宽度。

4

1 回答 1

0

使用 android:stretchColumns,您可以决定允许拉伸哪些列(放在 TableLayout 标签中)。

android:stretchColumns="0"
android:stretchColumns="0,1,2"
android:stretchColumns="*"
于 2012-06-14T12:19:47.883 回答