如何在Android中仅使用一维缩放图像?

如何在Android中仅使用一维缩放图像?,android,android-imageview,Android,Android Imageview,我正在尝试缩放仅指定所需宽度的图像。高度将以保持纵横比的方式缩放。我使用的图像足够大,可以覆盖整个屏幕。我正在尝试的代码如下所示: <ImageView android:src="@drawable/logo" android:layout_width="100sp" android:id="@+id/imageView1" android:layout_height="wrap_content" android:scaleType="centerInsid

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

<ImageView android:src="@drawable/logo"
        android:layout_width="100sp" android:id="@+id/imageView1"
        android:layout_height="wrap_content" android:scaleType="centerInside"/>
如果我使用fitXY,图像将不会保留纵横比,并且当我使用centerInside时,图像不会缩放。。有什么想法吗


提前感谢您。

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,它非常有用

看看这个:我已经拿到了!!您必须使用属性android:adjustViewBounds=true和android:scaleType=fitXY。所以代码看起来像这样:问候!答案1评论中的解决方案