Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to understand how to use different density images for 1.6+?

I'm trying to understand how the res/drawables images should work with different screen densities. Right now I've got a 1.5 app, and for example, I have an image that is 100x100 pixels. When used on the Droid, it scales this image so it appears to be the same size relatively on that device (all other layout scaling is handled by me, using dip units).

So now I need to update my project and add three folders, right?:

  1. drawable-ldpi
  2. drawable-mdpi
  3. drawable-hdpi

so I'm going to put my 100x100 image in the -mdpi folder. If I want to make a version for the -hdpi folder - how do I know how much larger to scale it by? I mean it looks like by default it should be 1.5x bigger. But what happens if I make it 2.0x bigger, or the device I'm running on doesn't happen to have a density 1.5x that of the baseline G1? Won't my layouts start looking different on those devices?

Thanks

like image 431
Mark Avatar asked Dec 10 '22 18:12

Mark


1 Answers

ldpi, mdpi, and hdpi correspond to density "classes", not the actual density of the device.

For instance the G1 is a mdpi class device (160dpi) but its screen density is actually around 180dpi. The droid is a hdpi class device (240dpi) but its screen is 265dpi.

Bitmap scaling is based on the density class only. The actual screen density is ignored.

So a G1 will show mdpi bitmaps slightly smaller than a mdpi device with a true 160dpi screen, but this is a very small difference so it's not a big deal.

(Note that other dimension types, such as "in" and "mm", do take into account the screen density.)

So for densities you have 3 choices: ldpi (120), mdpi (160) and hdpi (240). Therefore, your 100x100 bitmap should be 75x75, 100x100, and 150x150 respectively.

For more info see: http://developer.android.com/guide/practices/screens_support.html#qualifiers

like image 63
Xavier Ducrohet Avatar answered May 06 '23 06:05

Xavier Ducrohet