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>
4

1 回答 1

1

阅读本文后,我认为最好的方法是先调整图像大小,然后再将其添加到行中。

TableLayout 的子级不能指定 layout_width 属性。宽度始终为 MATCH_PARENT。但是,layout_height 属性可以由孩子定义;默认值为 WRAP_CONTENT。如果子项是 TableRow,则高度始终为 WRAP_CONTENT。

于 2012-02-01T17:15:55.387 回答