Android:如何以相同比例扩展矩形图像以适合屏幕

标签 android imageview

我要在我的应用程序中设置以下矩形图像。

enter image description here

现在我试图在两边以相同的比例扩展图像,直到它适合屏幕。但我无法获得预期的图像。

enter image description here

到目前为止我的代码是:

<ImageView
    android:id="@+id/imgid"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/shayneward"
    android:scaleType="fitXY"/>

图片被截断并不重要,但它应该以相同的比例在两边扩展,直到适合屏幕。

最佳答案

android:scaleType="fitXY" 更改为 android:scaleType="centerCrop" 以获得您想要的行为。

不同的缩放选项记录在 ImageView.ScaleType 下.

关于Android:如何以相同比例扩展矩形图像以适合屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11094970/

相关文章:

android - 尽管在 API 19 中运行良好,但 API 级别 16 中未显示背景 ImageView

java - 错误 : no resource identifier for attribute 'srcCompat'

java - 发送到 Android 中的另一个 fragment 后, bundle 对象显示 null

javascript - firefox 窗口 innerheight 在缩放时不更新

android - 从 Android 中的互联网链接获取数据

android - 社交网络 FB、Twitter、G+ 等。在所有 3 个平台(iOS、Android 和黑莓)

android - 当应用程序处于 LockTask(KIOSK 模式)时,媒体播放器不播放任何音频

android - 在 imageview 中设置位图时出现 NullPointerException

android - ImageView 空指针错误

android - 用相机捕捉图像并在其上放置 ImageView ,如何?