2013-03-16 98 views
0

我有一个LinearLayout(水平),我正在使用它来显示3个ImageViews。当我第一次添加ImageView时,最后一张缩小了,因为图像太大而不适合3。这里是我的设计师屏幕看起来像:我的图像上的额外填充

after initially adding the three images

通知第三图像收缩。

要解决此问题,我在每个ImageView上设置了以下属性。

width: 0dp 
weight: 1 

这里是我的图片怎么看设置这些属性后:

after setting attributes

我运行到的是,即使画面已经缩水问题仍然存在空间在顶部和底部如以下图像中的蓝色矩形所示:

padding

我的问题是,为什么这个额外填充那里,我怎么能摆脱它?

谢谢

更新 - 加入我的布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/RelativeLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_gravity="center" 
android:background="@color/app_background_color" 
android:contentDescription="@string/game_image_button" 
android:gravity="center" 
tools:context=".EasyActivity" > 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/ImageView02" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:contentDescription="@string/game_image_button" 
     android:src="@drawable/ruler200x200" /> 

    <ImageView 
     android:id="@+id/ImageView01" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:contentDescription="@string/game_image_button" 
     android:src="@drawable/ruler200x200" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:contentDescription="@string/game_image_button" 
     android:src="@drawable/ruler200x200" /> 
</LinearLayout> 

</RelativeLayout> 
+0

只是好奇,什么尺寸是你原来的形象?我的意思是它是一个'x乘x'的方形图像? – 2013-03-16 22:34:46

+0

它是200x200像素,它位于drawable_hdpi – 2013-03-16 22:36:58

+0

如果您发布整个布局的代码将更容易理解 – lelloman 2013-03-16 22:45:09

回答

0

ImageViews支持不同ScaleTypes,默认为FIT_CENTERhere是其他选项。 FIT_CENTER意味着它将从高度和宽度开始,等于您的图像(在添加重量之前,您的图像在第一个屏幕截图中的样子)。我相信发生的事情是,它会根据您的layout_weight重新调整图像的宽度,并通过缩小图像以适应新的宽度来保持图像的宽高比。它离开高度成为原始高度并以结果为中心。

我认为其他规模类型之一会做你想做的。也许CENTERCENTER_INSIDE

0

您可以使用下面的代码

<Imageview..... 
android:adjustViewBounds="true" 
..../>