【问题标题】:Trying to get an ImageView to scale as the screen gets bigger试图让 ImageView 随着屏幕变大而缩放
【发布时间】:2017-06-16 16:43:40
【问题描述】:
我目前是 Android 开发的新手,我正在尝试让图像缩放以适应不同的屏幕尺寸。我做了一个drawable-hdpi、-mdpi和drawable-xdpi。在这些文件夹中,我放置了图像,但每个屏幕密度的尺寸不同(例如,对于 xdpi,我将图像放大)。我将imageView放在约束布局中,并将高度和重量设置为wrap_content。我期望图像与相应的可绘制图像大小相同,但对于更高的屏幕密度,它仍然非常小。有什么想法吗?我还阅读了大约 9 个补丁图像,但我不能将更大的图像添加到更高密度的可绘制文件夹中?
【问题讨论】:
标签:
android
image
android-layout
user-experience
【解决方案1】:
你应该改变 imageview 的 scaleType。
如果你想在保持纵横比的情况下缩放图像,你应该使用
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitcenter"/>
您可以尝试其他选项,例如 centerCrop 和 fitxy,然后查看结果
【解决方案2】:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
....
在ImageView中添加android:scaleType="fitXY"调整视图的宽高