ImageView不保持最大高度和宽度 [英] ImageView not keeping max height and width

查看:104
本文介绍了ImageView不保持最大高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用从用户照相馆检索到的.setImageURI(selectedImageUri)将图像加载到ImageView中.我的图片视图使用

I load an image into an ImageView using .setImageURI(selectedImageUri) that is retrieved from the user's photo gallery. I have the image view restrict the size with

android:maxHeight="150dp"
android:minHeight="150dp" 
android:maxWidth="150dp" 
android:minWidth="150dp"

直到您从图库中添加图像为止,一切都很好.然后,图像会忘记最大高度和宽度.它与显示器一样宽,并且图像上方和下方都有很多空间.我只需要添加一个scrollview即可查看图像并向下滚动.上方和下方有均匀的空间.有人遇到过这个问题吗?

It's fine up until the you add the image from the gallery. The image then forgets about the max height and width. It is as wide as the display and there is a lot of space above and below the image. I had to add a scrollview just to see the image and scroll down. there is an even amount of space above and below. Has anyone run into this problem before?

推荐答案

将以下内容添加到您的适当的功能)

Add the following to your XML code (Or use the appropriate function)

android:adjustViewBounds="true"

我不知道为什么这不是默认设置,因为似乎很多物品都需要使用它.仍然,将这种简单的逻辑添加到XML文件中将带来所有不同.

I don't know why this isn't a default, because it seems like it would be required for a large number of items. Still, adding this simple logic to your XML file will make all of the difference.

这篇关于ImageView不保持最大高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆