Android multiple screen sizes and density problems
Asked Answered
G

5

6

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.

Geilich answered 10/12, 2010 at 18:8 Comment(1)
I'm not concerned about distortion because of the nature of the images, my problem is that they don't always scale. On a G1, they don't scale at all and this is fine. On a Droid, they scale up because the density is reported properly (240), but on a Galaxy Tab, the images are all small and in the upper left hand corner of the screen because it reports 480px wide, but the density is still 160 - or at least reporting this way.Geilich
F
2

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

Fading answered 7/1, 2011 at 23:48 Comment(0)
I
1

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

Igbo answered 10/12, 2010 at 19:28 Comment(3)
Yes, but the problem is that all devices don't seem to behave the same. If I have a 320x480 png in the drawable folder, on a G1 with 160dpi screen the image fits the full screen, on a droid with a 480x800 screen with 240dpi, the image fits the full screen. But then all of a sudden there are devices with 480x800 screens and 160dpi. So if I have 100+ images, my program will be HUGE if I have to create images for each resolution. Why aren't they scaling up for all devices like they do on the Droid?Geilich
Again, how are you drawing the images? ImageView? Background?Igbo
I'm using drawBitmap() in onDraw() on my games.Geilich
C
1

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.

Codycoe answered 6/2, 2011 at 21:35 Comment(1)
it should be res/drawable-xlarge-mdpi and not res/drawable-mdpi-xlargeBicameral
R
0

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

Reid answered 10/12, 2010 at 18:48 Comment(0)
K
0

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

Konikow answered 6/7, 2015 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.