Question

I have confusion regarding multi screens support in android. I have gone through article for multi screen support at android developer forum. My question is if app has 15-20 images that need to be shown full screen on device screen. Now if I want to support all screens what should i put in three drawable folders ldpi, mdpi & hdpi. Here what i have done

In ldpi - images of 240x320 resolution mdpi - images of 320x480 reolution hdpi - images of 720x800 resolution. (I am using same densities for all three resolution) I think this is not right approach.

What exactly I should do? Put images of different resolution in drawable-ldpi, drawable-mdpi & drawable-hdpi as above or should i use images of different densities 120 dpi, 160 dpi & 240 dpi. If i use images of different densities what should be their resolution(should 120 dpi resolution be 240x320, 160 dpi resolution 320x480 & 240 dpi resolution be 480x800). Or if i am using different dpi images their resolution should be same(320x480) for all densities .

Regards, Anuj

Was it helpful?

Solution

Ideally you should have drawables with different densities for different screens. You can use sizes you mentioned for your images. But you can also provide only high-dpi images and they will be downscaled to match user's device screen density.

Also if you want images to be shown in fullscreen, you possibly have to have different versions of these images for landscape and portrait orientations and for long and not long screens.

And finally you can use an ImageView widget for proper image scaling on different devices.

OTHER TIPS

Anujprashar, there is no easy answer to your question. The different densities specifications (hdpi, mdpi, ldpi) just refer to an average range of densities (i.e. hdpi is around 240 ppi). However, hdpi could refer to a large number of different resolutions (e.g. Motorola Droid is hdpi, resolution 480x854; Nexus One is hdpi, resolution 480x800). So there is no fixed size image you can use to fit perfectly all devices full screen.

My suggestion is if at all possible, either avoid using a layout that requires the images to be the exact size of the screen, or instead provide an image larger than the majority of the resolutions for that target density (e.g. 500x900) leaving extra margins that may be cropped off (think of it as a bleed, if you're familiar with that concept for print).

Or more simply, if you do not require them to be displayed 1:1 at their original pixel resolution, you can simply set the scaleType of an ImageView to centerCrop, and its width and height to fill_parent. This will expand (or condense) the image to fit the container, cropping off pixels if the aspect ratio is not correct.

The more difficult (and far less efficient) method would be to have a different image for each screen resolution, and a method in your onCreate() to retrieve the screen dimensions and set the image according to the values you get back.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top