2011-05-01 97 views
2

我有一个表布局shown.I有很多行。我已经使用android:strechcolumns =“1”来拉伸每一行的第二列。这就是无处不在的情况。表布局大小

但在第五行我有2个fields.I希望他们占据等于space.The行大小应该是相同以前row.I的希望行的整体尺寸保持相同的screeshot.Also我已经在屏幕截图中指出了所有行应该位于的边界。

这怎么办?

<TableRow> 
    <TextView 
     android:gravity="right" 
     android:paddingTop="10dip" 
     /> 
    <Spinner 
    android:id="@+id/depot_name_spinner"/> 
</TableRow> 

<TableRow> 
    <TextView 
    android:text="@string/product_name" 
    android:paddingTop="10dip" 
    android:gravity="right"/> 
    <Spinner 
    android:id="@+id/product_name_spinner" 
    /> 
</TableRow> 

<TableRow> 
    <TextView 
     android:text="@string/date" 
     android:gravity="right" /> 
    <Button 
    android:id="@+id/date_button" /> 
</TableRow> 

<TableRow> 
    <TextView 
     android:text="@string/measure_ltr" 
     android:gravity="right" 

     /> 
    <EditText 
    android:id="@+id/ltr_text" 
    android:layout_width="50dip"/> 
    <TextView 
     android:text="@string/measure_qts" 
     android:gravity="right" 
    /> 
     <EditText 

    android:id="@+id/qts_text" 
    /> 
</TableRow> 

enter image description here

感谢

回答

2

您不仅可以TableRow添加到表中。只需使用一个简单的LinearLayout并将所有原始内容放入其中。我认为它必须解决你的问题。

编辑:另外,您可以用LinearLayout所有小工具添加到TableRow并设置LinearLayoutandroid:layout_span=2

<TableRow> 
    <LinearLayout 
     android:layout_span="2"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/measure_ltr" 
      android:gravity="right"/> 
     <EditText 
      android:id="@+id/ltr_text" 
      android:layout_width="50dip" 
      android:layout_height="wrap_content"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/measure_qts" 
      android:gravity="right"/> 
     <EditText 
      android:id="@+id/qts_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
</TableRow> 

我还没有尝试过,但希望它会工作。

+0

我使用的时刻,但不能复制,你知道,我在表行使用STRECH列构成行的默认大小畅游以前row.Do的确切高度? – rogerstone 2011-05-01 09:50:45

+0

我不知道如何获得'TableRow'的默认高度。但我增加了另一个答案的答案。 – Michael 2011-05-01 10:17:17

+0

检查了你给我的那段代码。看起来像android:span不适用于线性布局。我检出了文档。它不在那里.xml给了我一个错误。 layout_span'可以在表行内使用,但其值必须在引号: – rogerstone 2011-05-03 15:13:15

1

尝试使用机器人:体重。一旦布局布局完成后,这将划分剩余的空间,而这正是您想要的。我的意思是你可以定义每个视图应该使用的空间比例。看看下面的这个例子。

<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> 
    <TableRow> 

    <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" 
        android:layout_height="wrap_content" android:weightSum="100">  // Mention Weightsum as 100 so that its easy to split among your views. 

     <TextView android:id="@+id/row1Label" 
      android:layout_width="0dip" android:layout_weight="60"  // This will occupy 60% of the remaining space 
      android:layout_height="wrap_content"> 
     </TextView> 

     <TextView android:id="@+id/row1Label" 
      android:layout_width="0dip" android:layout_weight="40"  // This will occupy 40% of the remaining space 
      android:layout_height="wrap_content"> 
     </TextView> 

    </LinearLayout> 

    </TableRow> 

    <TableRow> 

    <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" 
        android:layout_height="wrap_content" android:weightSum="100"> 

     <TextView android:id="@+id/row2Label" 
      android:layout_width="0dip" android:layout_weight="60"  // This will occupy 60% of the remaining space 
      android:layout_height="wrap_content"> 
     </TextView> 

     <TextView android:id="@+id/row3Label" 
      android:layout_width="0dip" android:layout_weight="40"  // This will occupy 40% of the remaining space 
      android:layout_height="wrap_content"> 
     </TextView> 


     // You can more views and distribute the space accordingly.... 

    </LinearLayout> 

    </TableRow> 

...........

有了这个,你可以做到这样的事情 enter image description here

您可以分割在任何你想要的方式表行区域。这可以仅使用线性布局来完成,因为其他布局没有这种权重选项。我广泛使用这种方法来创建复杂的视图。希望它可以帮助你。