ImageView适合不拉伸图像

问题描述 投票:18回答:2

是否有可能我的ImageView适合所有屏幕尺寸而不会使图像看起来拉伸?

我尝试使用fill_parent> wrap_content将所有比例类型更改为背景和src

但仍然。如果图像不小,它只是看起来拉伸..

例:

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="centerInside"
    android:adjustViewBounds="true"
    android:background="@drawable/background" />

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    android:background="@drawable/background" />

这两个适合宽度,但图像被拉伸..但当我将其更改为src时,图像只是居中和小。

android android-layout uiimageview imageview
2个回答
31
投票

没有内置的比例类型允许ImageView自动升级图像并保持其纵横比不变。升级的唯一比例类型是fitXY,它不会尊重纵横比,因为你也发现了自己。

话虽这么说,这个话题已经被不止一次访问过了。看看针对类似问题提出的一些建议:

我肯定会更多,所以值得使用顶部的搜索框。


2
投票

只需向ImageView添加一个属性即可实现

android:adjustViewBounds="true"
© www.soinside.com 2019 - 2024. All rights reserved.