0

我正在尝试缩放仅指定我想要的宽度的图像。高度将以保留纵横比的方式缩放。我使用的图像足够大,可以覆盖整个屏幕。我正在尝试的代码如下所示:

<ImageView android:src="@drawable/logo"
        android:layout_width="100sp" android:id="@+id/imageView1"
        android:layout_height="wrap_content" android:scaleType="centerInside"/>

如果我使用“fitXY”,则图像不会保留纵横比,并且当我使用“centerInside”时,图像不会缩放。知道吗?

先感谢您。

4

1 回答 1

0

Jesbomar 的解决方案具有漂亮的格式:

<ImageView 
    android:src="@drawable/logo" 
    android:adjustViewBounds="true" 
    android:layout_width="100sp" 
    android:id="@+id/imageView1" 
    android:layout_height="wrap_content" 
    android:scaleType="centerInside" 
    /> 

我更喜欢 scaleType="centerInside" 而不是 "scaleXY" 以使图像尽可能大而不改变纵横比或裁剪图像的任何部分。

感谢您回来提供您的解决方案 jesbomar,这非常有帮助。

于 2015-12-11T23:33:29.353 回答