2016-08-24 5 views
0

TableRow를 사용하고 있습니다. 테이블 행 내에서 일부 textview가 있습니다.TableRow 안에 Table 열의 배경색을 설정하는 방법

내 요구 사항에 따라 텍스트 뷰 높이가 wrap_content 여야합니다.

배경색을 지정하면 Textview로 설정됩니다. 전체 행을 채우지는 않습니다. 그냥 아래 이미지

enter image description here

하지만 내가 필요로하는 배경은 전체 열 대신 텍스트 뷰 설정해야합니다입니다 같은

.

여기에 내 코드가 추가되었습니다.

<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"당신의 요구 사항 tablow에서 선형 또는 상대적인 장소 배경색을 취하십시오.이 배치 장소 textview.

1

모든 TextView에서 layout_height를 match_parent로 변경하십시오.

+0

고맙습니다. 작동 중입니다. :) – MathaN

+0

@MathaN 내가 도와 주면 제 대답을 수락하십시오 :) 감사합니다 – mayosk

+0

하지만 두 가지 대답을 수락 할 수 없습니까? – MathaN

1

높이가 부모를 감싸고 싶지 않으므로 3 개의 선형 레이아웃을 만들고 배경을 textView의 배경색으로 정의해야합니다. 그러나 당신이 그것을 필요로하는 이유를 공유 할 수 있다면, 아마도 더 좋은 솔루션을 제시 할 수있는 오버 헤드가 될 것입니다.