2012-02-01 72 views
0

有谁知道一种方法来使用具有相同高度的行数填充父项的表格布局?填充父项但具有相同高度的行的表格布局

在下面的布局中,所有行将具有相同的高度,但是如果添加了第一行的图像视图,则该行将拉伸以适合图像的高度。有没有什么办法让行只显示图像视图的一部分,或者任何可以放在行中的内容?

<TableLayout android:id="@+id/table_layout" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"> 

    <TableRow android:id="@+id/row1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:background="#FF0000FF"> 
    </TableRow> 

    <TableRow android:id="@+id/row2" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:background="#FF00000"> 
    </TableRow> 

    <TableRow android:id="@+id/row3" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:background="#FF00FF00"> 
    </TableRow> 

    <TableRow android:id="@+id/row4" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:background="#FFFF0000"> 
    </TableRow> 

    <TableRow android:id="@+id/row5" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:background="#FFFFFFFF"> 
    </TableRow> 

</TableLayout> 

回答

1

在阅读this,我认为这样做是将它添加到该行之前,首先调整图像的最佳方式。

TableLayout的子项无法指定layout_width 属性。宽度总是MATCH_PARENT。但是,layout_height 属性可以由孩子定义;默认值是WRAP_CONTENT。如果 这个孩子是一个TableRow,那么这个高度始终是WRAP_CONTENT。

相关问题