2016-08-24 78 views
0

我有TableRow。在表格行內我有一些textview。如何設置TableRow中Table列的背景色

對於我的要求,Textview高度應該是wrap_content。

如果我給背景顏色它將被設置爲Textview。它不會填滿整行。

就像下面的圖片

enter image description here

但我需要的是背景應設置爲整列而不是TextView的。

這裏我添加了我的代碼。

<TableRow 
     android:id="@+id/tableRow" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" 
     android:gravity="center" 
     android:minHeight="?attr/actionBarSize"> 


     <TextView 
      android:id="@+id/subject" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="198" 
      android:background="@color/colorAccent" 
      android:gravity="center" 
      android:text="Subject" 
      android:textColor="@color/colorWhite" 
      android:textStyle="bold"></TextView> 


     <TextView 
      android:id="@+id/date" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="98" 
      android:background="@color/colorSecondary" 
      android:gravity="center" 
      android:text="Date" 
      android:textColor="@color/colorWhite" 
      android:textStyle="bold"></TextView> 

     <TextView 
      android:id="@+id/Time" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="98" 
      android:background="@color/colorPrimaryDark" 
      android:gravity="center" 
      android:text="Time" 
      android:textColor="@color/colorWhite" 
      android:textStyle="bold"></TextView> 

    </TableRow> 
+0

在ID tableRow中設置背景顏色而不是主題。用/>替換>。它使更整潔的代碼。 – apmartin1991

回答

1

if textview android:layout_height =「wrap_content」是你的要求在tablerow中取線性或相對位置的背景色。在這個佈局的位置放置textview。

1

只需在所有TextView中將layout_height更改爲match_parent即可。

+0

謝謝它的工作:) – MathaN

+0

@MathaN如果我幫你,請接受我的回答:)謝謝 – mayosk

+0

但是不可能接受兩個答案我是對的嗎? – MathaN

1

由於您不希望高度在這種情況下需要換成父級,所以您需要創建三個線性佈局並將其背景定義爲textView的背景顏色。但是,如果你能分享爲什麼你需要它,那麼它的開銷可能比建議更好的解決方案要好。