Search code examples
androidscreenresolution

Android: support multiple screen


I am trying to program to multiple screens. I currently have two devices:

Samsung Galaxy S2 with a screen of 4 inches: 480x800 density: 1.5 Height (dp): 533.3333 Width (dp): 320.0 screenLayout: 34 = 0010 0010

Samsung Young with a screen of 3.2 inches: 320x480 density: 1.0 Height (dp): 480.0 Width (dp): 320.0 screenLayout: 18 = 0001 0010

So, the devices differ in density and screenLayout (SCREENLAYOUT_LONG_YES vs. SCREENLAYOUT_LONG_NO).

I prepared image buttons in two sizes and put them in drawable-mdpi (for the higher resolution) and in drawable-ldpi (for the lower resolution). The image buttons have the same name.

I also wrote two different layouts, yet, with the same file name and put them in the layout folder (for the higher resolution) and in the layout-small (for the lower resolution).

I left the Java code with no changes, i.e., it doesn't check the resolution for selecting high or low resolution.

The problem is, that the two devices go to the same folder, both in layout and both in drawable.

What am I doing wrong? What is the right way to handle multiple screen sizes in android?

Thanks! AJ


Solution

  • Add layout in Every Folder

    res/layout/my_layout.xml             // layout for normal screen size ("default")
    res/layout-small/my_layout.xml       // layout for small screen size
    res/layout-large/my_layout.xml       // layout for large screen size
    res/layout-xlarge/my_layout.xml      // layout for extra large screen size
    res/layout-xlarge-land/my_layout.xml
    

    in manifest file

    <supports-screens android:resizeable=["true"| "false"]
                      android:smallScreens=["true" | "false"]
                      android:normalScreens=["true" | "false"]
                      android:largeScreens=["true" | "false"]
                      android:xlargeScreens=["true" | "false"]
                      android:anyDensity=["true" | "false"]
                      android:requiresSmallestWidthDp="integer"
                      android:compatibleWidthLimitDp="integer"
    

    and for more detail link