2012-06-14 43 views
2

我正在开发一个Android应用程序。不允许TextView填充整列

我有这样的布局:

enter image description here

我不想让一个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”,我无法改变它的宽度。

回答

0

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

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

谢谢,但我不明白你的答案。我已将'android:stretchColumns =“*”'放在我的TableLayout标记中。 – VansFannel