Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ImageView get scaled image on screen

Tags:

android

image

In my code I'm loading image from source into my ImageView. ScaleType of this image view is FIT_CENTER. My original image is far bigger than on screen. Is it possible to obtain width and height or scale ratio of image on screen? I can do it manually like based on orientation of image, calculate ratio of area that ImageView is in and ratio of image itself. After ratio I can assume which dimension is fitted (like width or height) and so on...

Is there any other easiest way to do it?

like image 918
zmeda Avatar asked Mar 02 '26 11:03

zmeda


1 Answers

You can scale your image retaining aspect ratio by setting the adjustViewBound to true and scaleType to fitXY.

android:adjustViewBounds="true"
android:scaleType="fitXY"
like image 88
redGREENblue Avatar answered Mar 05 '26 01:03

redGREENblue



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!