Victor CS
Victor CS

Reputation: 71

Problems in supporting multiple resolutions

I am having trouble managing my application layouts in three different resolutions; 720x1280, 1080x1920 and 1440x2560.

In drawable-xhdpi folder is the corresponding images to 720x1280 resolution. The folder drawable-xxhdpi is the corresponding images to 1080x1920 resolution and in drawable-xxxhdpi to 1440x2560.

I began to adjust the screens in layout folders. The layout-sw360dp was setting screens for 720x1280 and the layout-sw480dp the 1080x1920.

When testing in the emulator 720x1280 all settings worked perfectly. But to test the emulator 1080x1920, oddly taking this information in layout-sw360dp folder and not the layout-sw480dp.

In the case of adjusting each folder layout-sw360dp and layout-sw480dp, I'm using margin with values ​​in 'dp' and emulator higher values ​​(layout-sw480dp) are being dropped are being used and the values ​​of the layout-sw360dp.

How can I manage three screen sizes correctly?

Upvotes: 0

Views: 627

Answers (1)

NigelK
NigelK

Reputation: 8490

Well designed Android applications cater for varying screen sizes, the screen size being a function of both resolution and density. Using several layout-sw###dp folders allows you to vary the layout according to the width of the display, e.g. showing fewer elements and controls on a small screen and perhaps more detail on a large one.

The 'sw' in the layout folder name is the 'shortest width' a display must have in device independent pixels (dip). One dip = 1 real pixel on a 160 density screen. So on a 320 density screen, 2 real pixels make up one dip.

Your nexus 5 has 480/160 = 3 real pixels per dip. So with a width resolution of 1080, that is 360dip wide. Your nexus 4 has 320/160 = 2 real pixels per dip. So with a width resolution of 768, that is 384dip wide. Neither device is more than 480 dip wide so both use the sw360dp folder.

Both devices are physically very similar in size. The Nexus 5 (5.4inch screen) has more pixels than the Nexus 4 (4.7inch screen) but the pixels are physically smaller. So it is correct that the same layout is used for both. The UI should look the same on both devices, assuming you correctly specify the size and layout of your various UI elements in dip.

As a further example, I have an old tablet (10inch screen) with a resolution of 800x1280 and a low density of 149, hence is 859dip wide. You can comfortably display far more info on a screen that size than on a Nexus 4/5, hence you might consider creating a layout-sw720dp for that.

So you appear to be doing exactly the right thing already by designing different layouts for different screen sizes. Just remember that resolution is not the same thing as screen size. Screen size is a combination of resolution and density.

As for your drawables, you are also already doing the right thing by using drawable-xhdpi, drawable-xxhdpi etc with appropriate resolution images in each one. So for example a small device with an extremely high density would likely use the 1440x2560 images and the sw360dp layout. My low res tablet would use the 720x1280 images, unless you'd put something in drawable-mdpi which is where it would look first.

So firstly you'd create appropriate resolution images in the drawable folders so that they would look as good as possible on different resolution screens. Then create appropriate swxxxdp for your layouts so they take up the appropriate space depending on the physical screen size, i.e. make good use of available screen space on large devices and don't clutter up small ones. It's likely you would want to go further and create -land and -port versions of each as well.

It is worth noting that even if you only have one layout folder and one drawable folder, your application will still work on all devices. Android simply looks for the best choice and if there is only one, it'll use that. Adding in the various folders simply allows you to make your app look as good as possible on a range of devices.

Everything I have discussed here and more is explained in detail at http://developer.android.com/guide/practices/screens_support.html.

Upvotes: 2

Related Questions