android - Android图像根据设备屏幕尺寸更改图像尺寸
问题描述
我有一个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" />
如果这很重要,我已将该图像的不同分辨率的多个副本插入到不同的可绘制文件夹中
解决方案
<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
推荐阅读
- node.js - 编写文件 async node.js ,了解为什么不起作用
- android - GitHub GraphQl api v4 return "Cannot query field repository on type Query"
- javascript - JavaScript:尝试使用由于某种原因无法运行的类函数
- java - Loop is turning my negative integer positive in java
- ios - 在单个 UIButton 上有多个宽度约束是什么意思?
- python - 用色调颜色为极坐标图着色,在 0 处没有不连续性
- bash - 将 file_name 部分附加到文件的每一行,递归地附加到多个文件
- css - 如何将多个 css 文件和 javascript 文件编译成一个文件?
- go - 当你从一个频道读取并且你正在推送到另一个频道时,你如何编写一个不会挂起的函数
- android - androidx.appcompat.view.menu.ActionMenuItemView 无法转换为 android.view.MenuItem