How mdpi, hdpi, xhdpi folder works? How mdpi, hdpi, xhdpi folder works? android android

How mdpi, hdpi, xhdpi folder works?


You can create different graphic objects for use at different pixel densities. Android treats mdpi (160 pixels/inch) as the base density. So for mdpi devices, 1 dp = 1 pixel. At higher densities, there are more pixels per inch (240 for hdpi, 320 for xhdpi). Android attempts to make graphic images occupy the same physical dimensions on the screen regardless of the device pixel density. So if all it finds is an mdpi resource, and the device is hdpi, it will scale the graphic by 240/160 = 150%, and it will double the size of the graphic for xhdpi.

If you don't want this automatic scaling (which can make graphics look poor), you can simply supply your own version of graphic resources for use at higher densities. These graphics should be of the same size that Android would scale an mdpi resource.

Note that the pixels/inch that was stored in the image file has nothing to do with this. It's all based on where you put the graphics files in the resources directory for your project. Any graphics placed in res/drawable are assumed to be properly sized for mdpi displays, as are graphics placed in res/drawable-mdpi. Image files that it finds in res/drawable-hdpi are assumed to be properly sized for hdpi displays, etc. When your program runs on a particular device, Android will first look for a graphic that matches the display density of that device. If it does not find one but instead finds one for a different density, it will use that and automatically scale the image based on the above rules.


When you request a resource for which you provide alternatives, Android selects which alternative resource to use at runtime, depending on the current device configuration. To demonstrate how Android selects an alternative resource, assume the following drawable directories each contain different versions of the same images:

drawable/drawable-en/drawable-fr-rCA/drawable-en-port/drawable-en-notouch-12key/drawable-port-ldpi/drawable-port-notouch-12key/

And assume the following is the device configuration:

Locale = en-GB Screen orientation = port Screen pixel density = hdpi Touchscreen type = notouch Primary text input method = 12key

By comparing the device configuration to the available alternative resources, Android selects drawables from drawable-en-port.

The system arrives at its decision for which resources to use with the following logic:

enter image description here

Ref : How Android Finds the Best-matching Resource

Other References : Density independence , Providing Alternative Resources and Best Practices

And I will say that you should read complete page Supporting Multiple Screens, I don't think nothing will be better documentation than it...


I'm confused myself with all the screen size fragmentation but the basics are:1. You need to create various folders under layouts to work with your images2. Images will exist in the drawables folders also under various folders.3. You should have a basic /layout and /drawable folder to accompany non-specific folders4. Work from xhdpi then scale images down!

Examples for specific screen folders:/layout-hdpi/layout-xhdpi/drawable-hdpi/drawable-xhdpi

From what I know:480 x 800 is hdpi (older phones eg S2, HTC Desire etc)720 x 1280 is xhdpi (new phones eg S3, Galaxy Nexus etc)

Basically, Depending on the phone, android will grab resources from the necessary folder and if there is none then it will grab from the main '\layout' or '\drawable' folder. For example, the app running on a Galaxy Nexus will grab resources from '\layout-xhdpi' if the folder exists.