2013-07-25 44 views
0

我想要有一個Tablelayout以下屬性,android tableLayout列色問題

1.我想改變列的背景顏色。現在,如果我爲TextView設置背景,它將封裝內容並將該顏色設置爲不是整列。我想爲我的兩列添加不同的顏色。
2.更改兩列之間的空間(可能是邊框)。
有人做過這樣的事情請幫幫我。由於

<TableLayout 

    android:layout_gravity="center" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dip" 
    android:layout_margin="2dip" 
    android:orientation="vertical" > 

    <TableRow 
     android:padding="3dip" 
     android:id="@+id/tableRow1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dip"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:text="@string/NameLabel" 
      android:textColor="@color/black" 
      android:textSize="20sp" 
      android:background="#1DA43F"/> 

     <TextView 
      android:layout_marginLeft="5dip" 
      android:id="@+id/NameText" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:textAlignment="center" 
      android:layout_gravity="left" 
      android:text="@string/NameLabel" 
      android:background="@color/DarkRed" 
      android:textSize="20sp"/> 
       </TableRow></TableLayout> 
+0

向我們展示你當前的代碼。 –

+0

已更新代碼... –

+0

當您說'我應該能夠更改'時,您是指動態還是XML? –

回答

0
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/NameText" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@color/DarkRed" 
      android:text="@string/NameLabel" 
      android:gravity="center" 
      android:layout_marginRight="5dp" 
      android:textSize="20sp" />   

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="#1DA43F" 
      android:text="@string/NameLabel" 
      android:gravity="center" 
      android:textColor="@color/black" 
      android:layout_marginLeft="5dp" 
      android:textSize="20sp" /> 

    </TableRow> 

</TableLayout> 
0

從原始代碼:

  • 更換TableLayoutTableRowLinearLayout(不需要表,你只有一個行)

  • 添加android:paddingTextViews爲間距

  • 刪除android:layout_gravity="right"android:layout_gravity="left",並添加android:layout_weight="1"TextViews

+0

嗨,想要兩列不同的顏色。我認爲在行級指定顏色將爲這兩列賦予相同的顏色。編輯的問題。 –

+0

我有一個圖像顯示我想要的,但我無法上傳bcoz它需要一些更高的聲譽。 –

+0

更新了我的答案。 –