2010-11-11 103 views
1

我有一个TableLayout和3个TableRows,每个TableRow有3个ImageViews。每个ImageView都有适合Scale的fitCenter,以及每个此计算器的重量和宽度answer。现在所有的图像都可以缩放以适应该行,但每行都需要更高。下面是XML的摘录:TableRow高度越来越差

<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/avocado3),并且在activity的onCreate()中它获取了9张图像f从互联网rom并调用setImageBitmap()。

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

回答

3

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

尝试将设置adjustViewBounds设置为true。如果这没有帮助,请尝试设置一个固定的layout_height或使用maxHeight属性。

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

+0

甜! adjustViewBounds做到了!非常感谢。在调用setImageBitmap()之前,我刚做了一些其他工作来缩放图像。有时间采取这种手段。 – chad 2010-11-12 16:19:30