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?:
- drawable-ldpi
- drawable-mdpi
- drawable-hdpi
so I'm going to put my 100x100 image in the -md开发者_JAVA技巧pi 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
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
You can never be sure to cover all possible screen sizes. But if your layout arranges items automatically, you can set the absolute image size with px instead of dip.
Maybe you also want to use (small/normal/large) instead of (ldpi/mdpi/hdpi), because the former refer to screen size instead of density. Resource directory qualifiers
The behavior also depends on what your manifest declares, specifically the tag in the manifest (you can configure it using "manifest extras" in the first tab in ADT's Manifest Editor).
精彩评论