Android ImageView ScaleType and item height
Solution 1
Use the scaletype which seems best to you ( I guess you like what you see with fitCenter). The additional thing that you must do is
android:adjustViewBounds="true"
in your ImageView.
or you could go with FitXY but sometimes the result is not exactly what you want.
Solution 2
use android:scaleType="fitXY"
Solution 3
Could you use FitXY? This would work if you knew the size of the area you were putting the image into. CentreInside may also work, I've used this to scale down images, but I think it depends if you've control of the size of the bounding layout element.
Comments
-
Alin almost 2 years
Things looked quite simple first but in the end the result is not good. I have an image which has a width larger than screen's width. So I need to scale it down in my imageview. I looked over the ScaleType options and tried them all but none is ok. First
"center"
only displays the image centered on the layout, no scaling done."fitCenter"
scales the image to fit in my layout but has a major drawback: the height of the item remains as it would have the large image in it. Take a look at the second screen in the attached image. How can I force the list item, to reduce its height to wrap both the text and the image ? -
Alin about 12 yearsYes, this was the missing property. Works fine with adjustViewBounds and fitCenter
-
Gnanam R about 11 yearsI have image of 1000*800 but I cant get the full ImageView using any of these properties.. if any combination lies with it. pls help me out
-
Shubhayu about 11 yearsWill need more info, like whether the imageview is in a layout which is smaller that your image size, and how is the image being set.
-
Mahdi almost 10 years@Shubhayu: I have a problem that wanna stretch my image to my Imageview and keep it ascept ratio. I wanna use such a image on for example for title image that must shown in all size screens.
-
Shubhayu almost 10 years@Kenji If you want to stretch the image, then you must make sure that your ImageView is of the same aspect ratio as that of your src image and then use fitXY in scaleType. If you don't maintain the aspect ratio then any of the other scaleTypes will lead to cropping of the src image or empty space showing your imageview's background.