2013-07-25 42 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

更新了我的答案。 –