2011-04-26 4 views
3

여러 행으로 된 TableLayout을 만들고 각 행마다 서로 다른 열이 있습니다.다른 행에 다른 열이있는 TableLayout

다음 목록보기보기. 목록 뷰의 각 행에는 1 행 2 열만있는 테이블 레이아웃이 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:padding="6dip"> 
    <ImageView 
     android:id="@+id/color_label" 
     android:layout_width="12dip" 
     android:layout_height="fill_parent" 
     android:layout_marginRight="6dip" 
     android:background="#ffffff" /> 

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:stretchColumns="1"> 
     <TableRow> 
      <TextView 
       android:id="@+id/toptext" 
       android:gravity="left" 
      /> 
      <TextView 
       android:id="@+id/bottomtext" 
       android:gravity="right" 
      />  
     </TableRow>   

     <View android:layout_height="2dip" 
      android:background="#FF909090" /> 
    </TableLayout> 
</LinearLayout> 

결과는 다음과 같습니다.

enter image description here

나중에, 나는 더 TableLayout을 개선하고자합니다. 첫 번째 행은 2 개의 열을가집니다. 두 번째 행에는 4 개의 열이 있고 세로선에는 1,2 개의 열과 3,4 개의 열이 구분됩니다.

다음 코드를 사용합니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:padding="6dip"> 
    <ImageView 
     android:id="@+id/color_label" 
     android:layout_width="12dip" 
     android:layout_height="fill_parent" 
     android:layout_marginRight="6dip" 
     android:background="#ffffff" /> 

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:stretchColumns="1"> 
     <TableRow> 
      <TextView 
       android:id="@+id/toptext" 
       android:gravity="left" 
      /> 
      <TextView 
       android:id="@+id/bottomtext" 
       android:gravity="right" 
      />  
     </TableRow>   

     <View android:layout_height="2dip" 
      android:background="#FF909090" /> 

     <TableRow> 
      <TextView 
       android:id="@+id/col1" 
       android:gravity="left" 
       android:text="Column 1" 
      /> 
      <TextView 
       android:id="@+id/col2" 
       android:gravity="right" 
       android:text="Column 2" 
      /> 
      <TextView 
       android:id="@+id/col3" 
       android:gravity="left" 
       android:text="Column 3" 
      /> 
      <TextView 
       android:id="@+id/col4" 
       android:gravity="right" 
       android:text="Column 4" 
      />    
     </TableRow>   


     <View android:layout_height="2dip" 
      android:background="#FF909090" /> 

    </TableLayout> 
</LinearLayout> 

결과는 다음과 같습니다.

enter image description here

그러나, 테이블 레이아웃의 두 번째 행은 내가 원하는 것이 아닙니다. 내가 갖고 싶은 것은 이것과 같습니다.

enter image description here

어떻게 위의 효과를 달성하기 위해 내 XML을 향상시킬 수 있습니까?

답변

1

다른 항목 렌더러에 대해 사용자 고유의 드로어 블 xml (res/drawable-[h|m|l]dpi)을 만들고 배경으로 설정할 수 있습니다.

이 방법으로 모든 종류의 테두리, 도형 등을 얻을 수 있으며 adaptergetView 방법에서는 필요한보기를 적절한 backgroundDrawable으로 부 풀릴 수 있습니다.

+0

나는 또한 동일한 요구 사항을 가지고 있지만 별도의 XML을 가지고 있고 테이블을 가로로 스크롤하면 제대로 움직이지 않는다. 내가 한 헤더에서 한 헤더는 하나의 XML로 선언되고 행은 하나의 XML로 선언되며 해당 XML은 해당 활동에서 부풀려 있습니다.하지만 이제는 두 가지가 서로 경쟁합니다. 맨 아래로 이동하면 어떤 일이 발생합니까? 열이 움직이지 않습니다. 우리는 스크롤 뷰 내부에 listview를 놓을 수 없다. –

관련 문제