2016-08-24 33 views
0

TableRowを持っています。テーブルの行の中で私はいくつかのテキストビューを持っています。TableRow内のTableカラムの背景色を設定するには

私の要件に合わせて、テキストビューの高さを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

Textview android:layout_height = "wrap_content"はあなたの必要条件ですtablerowでは線形または相対的な場所の背景色を取ってください。

1

すべてのTextViewでlayout_heightをmatch_parentに変更するだけです。

+0

ありがとうありがとうございます:) – MathaN

+0

@MathaNもし私があなたを助けたら、私の答えを受け入れてください:)ありがとう – mayosk

+0

しかし、2つの答えを受け入れることはできません私は正しいですか? – MathaN

1

この場合、高さをラップする必要はないので、3つの線形レイアウトを作成し、backgroundをtextViewの背景色に定義する必要があります。しかし、あなたがそれを必要としている理由を分かち合うことができれば、それはかなりのオーバーヘッドになるかもしれません。

関連する問題