Search code examples
androidandroid-layoutandroid-5.0-lollipopandroid-4.2-jelly-bean

android layout support for all screen sizes with support to pre lollipop and above lollipop devices


This is my first android app, I am stuck on how to group layouts for small, medium and large screen sizes and also how to support pre lollipop devices and above lollipop devices?

layout-small

layout-small-v21

layout-normal

layout-normal-v21

layout-large

layout-large-v21

whether the directory names listed above are correct? or else can someone tell me how to achieve this?


Solution

  • To give the support to all screen sizes using different layout folders you have to follow these folders structure.

    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 // layout for extra large in landscape orientation
    

    And to give respective support enable in manifest.xml

    <supports-screens android:smallScreens="true" 
          android:normalScreens="true" 
          android:largeScreens="true"
          android:xlargeScreens="true"
          android:anyDensity="true" />
    

    And for images respective to all screen resolutions use drawable folder structure:

    res/drawable-mdpi/ic_launcher.png        // bitmap for medium density
     res/drawable-hdpi/ic_launcher.png        // bitmap for high density
     res/drawable-xhdpi/ic_launcher.png       // bitmap for extra high density
    

    To give a support to before and after lollipop api. You have to decide minimum api level and max api level for app support.

    Suppose for your app you want: Min. api level = 15 and Max. api level = 23

    In Eclipse IDE: In Manifest.xml add

    <uses-sdk
            android:minSdkVersion="15"
            android:maxSdkVersion="23"
            android:targetSdkVersion="23" />
    

    In AndroidStudio IDE: In build.gradle add

    defaultConfig {
            ...
            minSdkVersion 15
            maxSdkVersion 23
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
            ....
        }