Search code examples
androidimageresolutiondpi

Supporting android resolution screens: Understanding


I didn't really understand the DP measure, even though I've read about it 2 times.

Let's say I have an image it's resolution is: 400 X 400 PX.

And I want to put it as background image to my app. and I'm putting the same image on the different drawable folders(ldpi,mdpi,...)

Would the image strech? I don't know what resolution the image should be on the different drawable folders so it will fit the devices.


Solution

  • Your base density is mdpi. So your 400x400 dp image will be rendered as is on mdpi devices only. If you want the same size on ldpi, you have to scale your image by 0.75. For hdpi your image needs to be 1.5 times bigger and for xhdpi devices, 2.0 times the size of your mdpi.

    As mdpi is your base, I always put drawables in res/drawable-mdpi folder while developing. Once I got code ready for release I add hdpi resources to res/drawables-hdpi. I personally do not care ldpi devices as mostly no device I target is lower density than mdpi and if anyone will have such, then I am fine with android framework doing the downscale. But the upscaling is other story - you will always get bad results (blurry images) as you simply cannot technically make bigger bitmap from smaller without artifacts (no, CSI lies ;) - you simply got not enough data so you have to extrapolate. So it's better to provide proper drawables yourself or your end users would complain and your app may look not as nice as it could.