0

我有一个用于显示 3 个 ImageView 的 LinearLayout(水平)。当我第一次添加 ImageViews 时,最后一个被缩小了,因为图像太大而无法容纳 3 个。这是我的设计器屏幕的样子:

在最初添加三个图像之后

注意第三张图片缩小了。

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

width: 0dp
weight: 1

以下是设置这些属性后我的图像的外观:

设置属性后

我遇到的问题是即使图像已经缩小,顶部和底部仍有空间,如下图中的蓝色矩形所示:

填充

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

谢谢

更新 - 添加我的布局文件

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

2 回答 2

0

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

我认为其他比例类型之一会做你想要的。也许CENTERCENTER_INSIDE

于 2013-03-16T23:09:23.860 回答
0

您可以使用以下代码

<Imageview.....
android:adjustViewBounds="true"
..../>
于 2017-11-08T04:03:49.473 回答