【问题标题】:Don't allow to TextView fill the entire Column不允许 TextView 填充整个 Column
【发布时间】:2012-06-17 11:04:56
【问题描述】:

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

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

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

【问题讨论】:

    标签: android layout tablelayout


    【解决方案1】:

    通过android:stretchColumns,你可以决定哪些列可以被拉伸(放在TableLayout标签中)。

    android:stretchColumns="0"
    android:stretchColumns="0,1,2"
    android:stretchColumns="*"
    

    【讨论】:

    • 谢谢,但我不明白你的回答。我已将android:stretchColumns="*" 放入我的 TableLayout 标记中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    相关资源
    最近更新 更多