2010-02-03 39 views
18

Tôi muốn tạo bố cục sau nhưng không hoạt động.bố cục bảng android rowspan

alt text http://toms-toy.de/rowspan.gif

<LinearLayout android:orientation="horizontal"...> 
    <ImageView ...></ImageView> 
     <TableLayout ...> 
         <TableRow..> 
           <ImageView ...></ImageView> 
           <ImageView ...></ImageView> 
           <ImageView ...></ImageView> 
         </TableRow> 
         <TableRow..> 
           <ImageView ...></ImageView> 
           <ImageView ...></ImageView> 
           <ImageView ...></ImageView> 
         </TableRow> 
     </TableLayout> 
    <ImageView ...></ImageView> 
</LinearLayout> 
+0

tôi thấy [này thật sự tốt đẹp tuto rial on tableLayout] (http://coderzheaven.com/index.php/2011/03/android-tablelayout/). – Max

Trả lời

33

tôi đặt này lại với nhau thật nhanh, cố gắng này:

alt text

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView android:layout_width="50dip" android:layout_height="100dip" android:background="#cc0000"/> 
    <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> 
     <TableRow> 
      <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#aaaa00"/> 
      <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#00aa00"/> 
      <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#aaaa00"/> 
     </TableRow> 
     <TableRow> 
      <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#00aa00"/> 
      <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#aaaa00"/> 
      <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#00aa00"/> 
     </TableRow> 
    </TableLayout> 
    <ImageView android:layout_width="50dip" android:layout_height="100dip" android:background="#cc0000"/> 
</LinearLayout> 
+3

Lý tưởng là chiều rộng của số lần xem hình ảnh nên là wrap_content và chiều rộng của tablelayout, 0dip. Sau đó, thêm layout_weight là 1.0 vào tablelayout. –

+0

Chỉ muốn cảm ơn Jeffrey vì điều này, tôi đã kéo tóc ra cố gắng tìm ra điều này và chỉ để mọi người đều biết, định hướng = "nằm ngang" là rất quan trọng! Tốt nhất, Mike – Mike

7

thử này:

<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <TableRow> 
     <TextView android:text="1-2, 1;\t" android:layout_gravity="center" /> 
     <TableLayout> 
      <TableRow> 
       <TextView android:text="1, 2;\t" android:layout_gravity="center" /> 
      </TableRow> 
      <TableRow> 
       <TextView android:text="2, 2;\t" android:layout_gravity="center" /> 
      </TableRow> 
     </TableLayout> 
    </TableRow> 
</TableLayout>