Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android图像根据设备屏幕大小更改图像尺寸_Android_Imageview_Android Drawable - Fatal编程技术网

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

Android图像根据设备屏幕大小更改图像尺寸,android,imageview,android-drawable,Android,Imageview,Android Drawable,我有一个imageView的宽度是“match\u parent”(每端都有一些边距) 由于不同的设备具有不同的宽度,因此图像不会填充imageView,而是根据我在哪个设备上查看图像,在每一端留有一些间隙 我尝试过android:adjustViewBounds=“true”但这会拉伸图像以填充严重扭曲内容的宽度 正确的方法是什么?我应该给android多个不同尺寸的图像副本吗(比如不同像素密度的多个可绘制文件夹) 更新 尝试将scaleType设置为“fitXY”,但这仍然会拉伸图像,而不会

我有一个
imageView
的宽度是
“match\u 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" />

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


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

这仍在拉伸图像。请尝试使用center cropno,fitcenter和viewbound,但centercrop在没有view ViewBounds的情况下工作。我几乎一无所知,因为我不知道您的图像有多大或多小,所以最好根据最可能的情况进行猜测:Dgreat,接受答案,编辑为有效答案。。。下次发布图片尺寸:D