Android图像会根据设备屏幕尺寸更改图像尺寸

时间:2019-08-21 13:13:04

标签: android imageview android-drawable

我有一个imageView,宽度为"match_parent"(两端都有边距)。

由于不同的设备具有不同的宽度,因此图像不会填充imageView,而是在两端各留一些间隙,这取决于我在哪个设备上查看图像。

我尝试过android:adjustViewBounds="true",但这会拉伸图像以填充宽度,从而严重扭曲内容。

正确的方法是什么?我应该为Android提供具有不同尺寸的图像的多个副本(例如针对不同像素密度的多个可绘制文件夹)吗?

更新

尝试将scaleType设置为“ fitXY”,但这仍在拉伸图像而不保持宽高比。

这是我的xml:

<ImageView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="110dp"
        android:scaleType="fitXY"
        android:src="@drawable/inner_map"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/header" />

如果这很重要,我已将具有该图像不同分辨率的多个副本插入到不同的可绘制文件夹中

1 个答案:

答案 0 :(得分:-1)

<ImageView
    android:id="@id/img"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop" />

https://developer.android.com/reference/android/widget/ImageView.ScaleType