ImageView not keeping max height and width

与世无争的帅哥 提交于 2019-12-20 10:58:50

问题


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"

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?


回答1:


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

android:adjustViewBounds="true"

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.




回答2:


I havent. So, I ll be just guessing

  1. Did you try defining a ScaleType option?
  2. Check for opposing layout attributes that can cause the layout inflater to ignore the desired width/height values.
  3. I suppose you tried this already but use just Layout_height /Layout_width instead of min/max attributes..


来源:https://stackoverflow.com/questions/9253637/imageview-not-keeping-max-height-and-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!