Handling multiple resolutions with a single layout.

SiflouSiflou USMember ✭✭

Hey Guys,

I searched on resolutions and I found that you have to have the drawing for ldpi,mdpi,hdpi and xhdpi and that it will pick the proper asset and that it should work resolution wize. But I have to work with only mdpi and all my layouts were made/tested with 320x480 device. I have to adapt it for other resolutions and I have problems because on other devices it comes out really ugly. Could you guys help me with that, is there an easy way out of it ? Thanks a lot :)



  • fbs419fbs419 USMember ✭✭

    See this post:


    All this also depends on what versions of Android you are using. Pre 3.2, they used ldpi, mdpi, etc. to differentiate directories to support various devices. Starting in 3.2, they went to a scheme where you can specify screen sizes, i.e. drawable-sw320dp, drawable-sw330dp, etc. You can use these numbers based on width, height, etc.

    This document:


    has a lot of info on that, but it doesn't explain everything.

    It's probably best to use the smallest width scheme, since if you run out of height, you can always scroll.

    After lots of testing and research, I find that Android figures out what to support based on code similar to this:

    Android.Util.DisplayMetrics dm = Resources.DisplayMetrics;
    int widthInDp = ConvertPixelsToDp(dm.WidthPixels);
    private int ConvertPixelsToDp(float pixelValue)
        var dp = (int) ((pixelValue)/Resources.DisplayMetrics.Density);
        return dp;

    So you can use a number up to and including this value, and it would work. For example, if you try this code on various devices, and for one device, widthInDp comes out 320, and on another device, it comes out 340, you could use drawable-sw320 for one and drawable-sw330 for another. If you have a tablet, and it comes out to 600, you could use drawable-sw550 (or whatever). You have to play with it a little bit.

    And if you want to support pre 3.2 and 3.2 +, you can mix and match. Devices using pre 3.2 versions of Android won't use these "sw" directories, so you have to provide the others as well.

Sign In or Register to comment.