여러 행으로 된 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>
결과는 다음과 같습니다.
나중에, 나는 더 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>
결과는 다음과 같습니다.
그러나, 테이블 레이아웃의 두 번째 행은 내가 원하는 것이 아닙니다. 내가 갖고 싶은 것은 이것과 같습니다.
어떻게 위의 효과를 달성하기 위해 내 XML을 향상시킬 수 있습니까?
나는 또한 동일한 요구 사항을 가지고 있지만 별도의 XML을 가지고 있고 테이블을 가로로 스크롤하면 제대로 움직이지 않는다. 내가 한 헤더에서 한 헤더는 하나의 XML로 선언되고 행은 하나의 XML로 선언되며 해당 XML은 해당 활동에서 부풀려 있습니다.하지만 이제는 두 가지가 서로 경쟁합니다. 맨 아래로 이동하면 어떤 일이 발생합니까? 열이 움직이지 않습니다. 우리는 스크롤 뷰 내부에 listview를 놓을 수 없다. –