Dimitrios Menounos
Dimitrios Menounos

Reputation: 555

Correct way to scale ImageView

It seems to me that the way android scales bitmaps, with dpi profiles, is not correct.

For example I have a 320x533 image, that is meant to cover the entire screen area, defined as such:

<ImageView
    android:src="@drawable/background"
    android:layout_width="320dp"
    android:layout_height="533dp" />

At hdpi (240 or 1.5) the image scales correctly to 480x800. However at a xhdpi (320 or 2.0) does not! That is the image becomes 640x1066 but the actual phone area could be 720x1280 or 1080x1920 or other similar resolutions.

I have tried to adjust ImageView.scaleType (every option) but still the image does not scale correctly. What do you think is the correct way to handle this? Should I subclass the ImageView and handle the scaling with Java or am I missing something fundamental?

Upvotes: 1

Views: 807

Answers (1)

user529543
user529543

Reputation:

"Should I subclass the ImageView and handle the scaling with Java" NO

you can get the DPI value and you can get the resolution value too. Than you can calculate the desired number of pixels.

Option 2 is: use different directories based on android dpi. ( not only drawable, a google search will tell you exactly how )

Upvotes: 2

Related Questions