TableRow高度被吹灭

时间:2010-11-11 21:14:55

标签: android imageview tablelayout tablerow

我有一个带有3个TableRows的TableLayout,每个TableRow有3个ImageView。每个ImageView都有fitCenter for Scale类型,以及每个堆栈溢出answer的权重和宽度。现在所有图像都缩放以适合行,但每行都需要更高的行。这是xml的摘录:

<TableLayout android:id="@+id/TableLayout01"
android:layout_height="wrap_content"
android:padding="10dip"
android:stretchColumns="0,1,2"
android:shrinkColumns="0,1,2"
android:layout_weight="1"
android:layout_width="wrap_content">
    <TableRow android:id="@+id/TableRow01"
    android:layout_width="fill_parent"
    android:layout_gravity="center_vertical|center_horizontal"
    android:baselineAligned="false"
    android:gravity="center_vertical|center_horizontal"
    android:layout_height="wrap_content">
        <ImageView android:id="@+id/image1"
        android:src="@drawable/avocado3"
        android:scaleType="fitCenter"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"/>
        <ImageView android:id="@+id/image2"
        android:src="@drawable/avocado3"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"/>
        <ImageView android:id="@+id/image3"
        android:src="@drawable/avocado3"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"/>
    </TableRow>
...
</TableLayout>

这是第一行:

first row

第一行的结尾和第二行的开头:

second row

ImageViews设置为一个小的drawable(@ drawable / avocado3),在活动的onCreate()中,它从互联网上获取9个图像并调用setImageBitmap()。

任何人对我做错了什么有任何想法?

1 个答案:

答案 0 :(得分:3)

默认情况下,scaleType仅更改实际图片的大小,但不会更改周围ImageView的大小。由于ImageView的高度设置为wrap_content,因此需要显示完整图像所需的所有空间,然后缩放图像以使其适合其宽度。

尝试将adjustViewBounds设为true。如果这样做无效,请尝试设置固定的layout_height或使用maxHeight属性。

查看层次结构查看器可能也有帮助:http://developer.android.com/guide/developing/tools/hierarchy-viewer.html

相关问题