Android: Optimize for high-dpi devices only but still support (small- and) medium-dpi screens

751 views Asked by At

I'm building a game with graphic assets in hdpi resolutions (hence I put the files in drawable-hdpi directory). I don't want to have a corresponding mdpi resolution of the images, and I will code everything in 240-dpi based pixel coordinates.

Is it possible to still allow mdpi and ldpi devices to run the app, by automatically scaling the graphics from the hdpi version?

2

There are 2 answers

0
Colin Stewart On BEST ANSWER

If you put the graphic assets in drawable (with no qualifier) they will be used by all 1.6+ phones and scaled as appropriate for the screen resolution of the phone. You only need to use hdpi if you want to provide different assets for different screen densities.

0
yincrash On

You should put the assets in the drawable-hdpi/ directory. Phones will scale them down automatically with the following ratio:

3:4:6:8
l m h xh

So your hdpi assets would scaled 3:2 on a mdpi device. If you only put them in the drawable/ directory, the system uses mdpi as a baseline, and your assets will actually be scaled up on hdpi devices.

Note: If a density qualifier is not defined in a directory name, the system assumes that the resources in that directory are designed for the baseline medium density and will scale for other densities as appropriate.

How to Support Multiple Screens
How Android Finds the Best-matching Resource