Android multiple screen sizes and density problems
I'm having a real problem with my drawables that I just can't seem to figure out.
The problem is this:
There are screen sizes at approximately 320x480, 480x800, 480x854
Then there are most commonly densities at 1.0 (160) and 1.5 (240)
Now, on a Droid, the screen size is 480x800 and the density is reporting using DisplayMetrics as 1.5
On the G1, it's 320x480 and reporting back at a density of 1.0
BUT tablet devices are reporting back at 480x800 with a density of 1.0 (160)
So, I'm going mad because I can put 320x480 images in the drawables-mdpi folder and 480x800 images in the drawables-hdpi folder, but on Tablet computers, no matter what it's not resizing up anything to a full screen.
Any help would be 开发者_运维问答greatly appreciated. I just want all of my 320x480 images to scale up regardless of the device.
You might be missing some tags in your manifest such as anyDensity
and supports...
. Decent tablet support only came with xlarge
(in Gingerbread I think).
Also if you are drawing yourself, you need to call setTargetDensity(actualDensity)
on your canvas, drawable, or bitmap (can't remember which of the three).
How are you applying the images? You can just use fill_parent for the layout_width/height of an ImageView, and select fitCenter for the scaleType.
It's perfectly correct for the Galaxy Tab to be reporting as medium dpi (although I thought the resolution of the Tab was 1024 x 600?), even though it is a high resolution. The dpi is a measurement of the size of the pixels (e.g. the number of pixels in an inch). So a 480 x 800 resolution in a 4" screen will have a higher dpi than a 480 x 800 resolution in a 7" display, simply because they are compressed into a smaller space.
You can actually add an extra drawables folder called drawable-large-mdpi
that could contain files for a large screened medium dpi device, such as the Tab (see here for more information on those qualifiers).
The tablet is doing something wrong. Google specifically made it possible for the hardware manufacturer to declare hardware mpdi even if the dpi is about 160. The Galaxy Tab does this: http://realmike.org/blog/2010/12/21/multiple-screen-sizes-with-processing-for-android/
You can try to add a res/drawable-mdpi-xlarge and add hdpi graphics here. xlarge was introduced in 2.3 I think, and older Android versions won't recognize this. You might want to try drawable-mdpi-large then (as per http://blog.alsutton.com/2010/07/03/android-tablets-and-mdpi-large/)
Adding extra drawable folders adds to the size of your apk. In general, tablets before Gingerbread or better Honeycomb are tricky on Android and I wouldn't bother to do special stuff for them if you can avoid it.
For scaling images without distortion or pixelization, Android uses images called 9-patch. Read more about them here:
http://developer.android.com/guide/developing/tools/draw9patch.html
But this is more or less helpful depending on how you choose to use the images. The 9 patch tool would be of no use for say, a wallpaper application for instance.
Here is another link I found on SO:
http://www.developer.com/ws/other/article.php/3889086
Follow the link you may require to create different combinations of screen size and densities res folders for your app. Go through different qualifier names and experiment with them.
http://developer.android.com/guide/practices/screens_support.html
精彩评论