【问题标题】:ImageView fit without stretching the imageImageView 适合而不拉伸图像
【发布时间】:2012-12-18 02:42:29
【问题描述】:

我的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" />

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

【问题讨论】:

  • 您要求的东西显然是不可能的。当然,除非您想要填充的图像和屏幕/视图恰好具有相同的纵横比。

标签: android android-layout uiimageview imageview


【解决方案1】:

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

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

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

【讨论】:

  • 赞成谢谢 MH... 啊。似乎是不可能的。 =_= 在 xml 中修复~ 调整宽度以适应屏幕确实会拉伸图像
  • 我已接受您的回答。我在另一个主题中发现您不能仅在 xml 上执行此操作。您必须在 java 中修复它。谢谢~
【解决方案2】:

你可以通过在 ImageView 中添加一个属性来做到这一点

android:adjustViewBounds="true"

【讨论】:

  • 谢谢!我一直在使用刻度类型寻找正确的答案。但是这一行使它变得非常容易。非常感谢
猜你喜欢
  • 2022-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-02
  • 2011-06-07
  • 1970-01-01
  • 2019-05-12
  • 1970-01-01
相关资源
最近更新 更多