Search code examples
androidscaleresolutionpixelandroid-screen-support

Android sizes, real concern. What folder to use?


I've read a lot about scaling in Android and there are a lot of different opinions. But I feel this is really important to understand so maybe someone could explain.

For instance, I'm making a game using a lot of bitmaps of .png-pics, I'm putting everything in the res/drawable/mdpi-folder. I only plan to launch this game for phones, so no tablets.

I'm using a galaxy nexus which is hdpi, and everything looks fine on it. But will it look fine on phones with mdpi and xhdpi? I'm not using any density pixels, I tried using canvas.setDensity(320) but then I read somewhere that this should be avoided.

Does anyone have any experience with this? because I have none, and can't test on other phones because all my friends have iPhones.

I'm just worried my bitmaps might look giant or tiny on other phones that are not hdpi like mine, which will of course ruin the game.


Solution

  • If you do not provide hdpi resources your game will look crappy on hdpi devices. Here's why - 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 (no big deal) but for hdpi your image needs to be 1.5 times bigger and for xhdpi devices, 2.0 times the size of your mdpi. So if there is no dedicated drawable, upscale would happen. And this rarely looks good (in most case you end up with blurry graphics). So 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.