darja
darja

Reputation: 5025

Android scales hdpi image on hdpi device

I have noticed that all the images in my application seems to be smaller than originals. For example.

I placed image on activity like this:

<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
           android:src="@drawable/ic_search_dark"
           />

I took a screenshot from the result and measured the image as 25x25:

http://petromi.com/get/86b23cdb63.png

But in it's actual size is 28x28:

http://petromi.com/get/fd68913104.png

Image has been placed to drawables-hdpi folder. Device is 1280x800 tablet. I have logged its display metrics as follows:

Log.d("Screen (%s, %s) - [%s, %s] [%s]", dm.widthPixels, dm.heightPixels, dm.xdpi, dm.ydpi, dm.densityDpi);

And I got:

Screen (1280, 736) - [160.0, 160.15764] [213]
Screen (800, 1216) - [160.0, 160.15764] [213]

(for portrait and landscape)

It was a surprise for me that Android scales images from drawable-hdpi on hdpi device. Is it OK? If yes, can you guys give me a link where such rules are described?

Upvotes: 1

Views: 243

Answers (1)

DeeV
DeeV

Reputation: 36035

If the device registers as an hdpi device, it will take images from the hdpi folder. It will then proceed to scale the image to the device's actual specs. This is normal.

The dpi for hdpi is 240. What you have is 213, so the image will still be scaled based on a 240 dpi setting.

If you do not want scaling of any kind, then you need to put the image in the drawable-nodpi folder.

Upvotes: 5

Related Questions