how to know which phone support which layout(hdpi , mdpi and xhpi)?

duggu picture duggu · Jun 3, 2013 · Viewed 18.3k times · Source

I'm a little confused about how to determine which phones support what layout types. I've done some research but haven't found a satisfying answer.

For example, I've found the below guide:

xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp

However, I still have some concerns:

  1. Samsung grand (480*800) and HTC wild fire S (320*480) both support MDPI. These screens have very different resolutions, yet have the same layout type?

  2. Galaxy note 2 (1280*720) support HDPI. If HD (720p) is only HDPI, when what device/resolution supports XHDPI?

  3. I've already asked a related question here: How to set layout on 7" two different tablet?.

  4. My most important question, however, is this: How do I know which devices or screen resolutions support each layout type?

Answer

Ritesh Gune picture Ritesh Gune · Aug 10, 2013

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).

AutoMatic Scaling by Android itself:

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.

Using different versions of graphics :

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 : 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.

As the ldpi, mdpi and hdpi refer to screen density, which means how much pixels can fit into a single inch.

the ratio in pixels between them is:

ldpi = 1:0.75
mdpi = 1:1
hdpi = 1:1.5
xhdpi = 1:2
xxhdpi = 1:3

so lets take an image with about the size of 100X100:

for mdpi it should be 100X100
for ldpi it should be 75X75
for hdpi it should be 150X150
for xhdpi it should be 200X200
for xxhdpi it should be 300X300

this way, for screens with the same size but different DPI, all the images seem the same size on screen.