2013-04-11 30 views
0

我想这个特殊的表格布局:android中的表格布局(span/shrink)?

Layout of table

在我目前的布局是较短的细胞是在像长文本的单元格大小相同:

wrong layout

如何必须这样做吗?

它应该看起来像第一张照片。

+0

我认为表格布局应该做的一部分是给你排列的列。你想要列不排队。我不确定它是否适合你。 – HalR 2013-04-11 02:12:34

回答

2

可能有这样做的更好的办法,其实我以前没有使用过TableLayout,但是下面的XML给出你要的基本布局:

<TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_span="4" 
       android:layout_weight="1" 
       android:text="Text" 
       android:gravity="center" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.25" 
       android:text="Text" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_span="3" 
       android:layout_weight="0.75" 
       android:text="Text that is longer than other cells" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.25" 
       android:text="Text" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.25" 
       android:text="Text" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.25" 
       android:text="Text" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.25" 
       android:text="Text" /> 
     </TableRow> 
    </TableLayout> 
+0

谢谢你。它的工作好:) – venni 2013-04-13 15:41:42

0

用心棒,你是对的,但是如果您使用

安卓layout_weight

你必须记住有关更换(在这种特殊情况下)的android:layout_width =” WRAP_CONTENT “与

机器人:layout_width =” 0dp“。

Here你有一个很好的参考。