ImageView 适合而不拉伸图像

2024-01-02

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

我尝试了所有比例类型,将其更改为背景和 srcfill_parent > wrap_content

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

example:

<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 时,图像只是居中且很小。


没有内置的秤类型允许ImageView自动放大图像and保持其纵横比不变。唯一进行放大的比例类型是fitXY,这不会尊重宽高比,正如您自己也发现的那样。

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

  • ImageView 一维适合自由空间,第二个评估以保持宽高比 https://stackoverflow.com/questions/6202000/imageview-one-dimension-to-fit-free-space-and-second-evaluate-to-keep-aspect-rat
  • 将图像适合 ImageView,保持宽高比,然后将 ImageView 调整为图像尺寸? https://stackoverflow.com/questions/8232608/fit-image-into-imageview-keep-aspect-ratio-and-then-resize-imageview-to-image-d
  • 调整 ImageView 大小以适应纵横比 https://stackoverflow.com/questions/12400113/resizing-imageview-to-fit-to-aspect-ratio

我确信会更多,所以可能值得使用顶部的搜索框。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ImageView 适合而不拉伸图像 的相关文章

随机推荐