zmeda
zmeda

Reputation: 2909

Android ImageView get scaled image on screen

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?

Upvotes: 3

Views: 2977

Answers (4)

Nguyen  Minh Binh
Nguyen Minh Binh

Reputation: 24453

There is another way to "auto-scale" your image. You should set the loaded bitmap as background of ImageView control instead of set as source. Hope this helps.

Upvotes: 0

redGREENblue
redGREENblue

Reputation: 3126

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

android:adjustViewBounds="true"
android:scaleType="fitXY"

Upvotes: 8

VenkaReddy
VenkaReddy

Reputation: 2881

hi set your scale type fitXY like as this. android:scaleType="fitXY"

Upvotes: 0

Axarydax
Axarydax

Reputation: 16623

Use ImageView's

getDrawable().getIntrinsicHeight()

Taken from this related question.

Upvotes: 0

Related Questions