【问题标题】:How do I display this image in Android?如何在 Android 中显示此图像?
【发布时间】:2010-11-15 11:19:03
【问题描述】:

如何在 Android 中显示具有以下配置的图像?

  • 保留原始纵横比(图片可以缩放,但不能拉伸)
  • 填充父级宽度
  • 与父级底部对齐

以下不起作用:

<ImageView
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:layout_alignParentBottom="true"
android:src="@drawable/background" />

使用上面的 xml,ImageView 采用父级的宽度,但 ImageView 内的图像没有。

【问题讨论】:

  • 如果您也能告诉我们什么不起作用会有所帮助吗?

标签: android imageview android-layout resolution-independence


【解决方案1】:

一些要点。 如果您想使用宽高比而不是 fitCenter,您应该尝试 centerInside:

Scale the image uniformly (maintain the image's aspect ratio) so
that both dimensions (width and height) of the image will be equal
to or less than the corresponding dimension of the view (minus padding). 

请记住,使用您的应用程序的设备可能具有不同的屏幕尺寸。 如果您的背景图片可以拉伸,我建议您尝试NinePatchDrawable

【讨论】:

  • 谢谢 Macarse。背景可以缩放,但不能拉伸。
  • 另外,fitCenter 不应该也保持纵横比吗?对不起。我发现 ScaleType 的文档有点混乱。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-23
  • 1970-01-01
  • 2015-10-21
  • 2013-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多