在图像视图中拉伸图像以适应 xml 中的屏幕

stretch image in imageview to fit screen in xml

我在drawable中有图片,需要作为背景使用。它需要拉伸以填满屏幕.. 我知道如何使用 java 代码将图像全屏拉伸。但是在 XML 中它自己如何做到这一点。

试试这个 属性:

android:scaleType="fitXY"

Here 您可以找到其他用于调整大小的常量值。

android:scaleType="fitXY" 将拉伸图像以适合 ImageView

的完整尺寸

尝试像这样实现您的 ImageView 并将 ic_launcher 更改为您自己的图像名称添加。

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

希望这会有所帮助。谢谢

我更喜欢使用 scaleType="centerCrop"。这样图像就不会超出其原始比例。