Design Layout For Multiple Screens

I am new in android, and want to design the layout which run in all screens of the android phone and tablet too ? Is their is a way to do this ?


Solution 1:

You need to create different layout for diff screen size. Support all screen you need to create following layout:

  1. Low density Small screens QVGA 240x320 (120dpi):

    layout-small-ldpi (240x320)  
    layout-small-land-ldpi (320x240)
    
  2. Low density Normal screens WVGA400 240x400 (x432) (120dpi):

    layout-ldpi  (240 x 400 )
    layout-land-ldpi  (400 x 240 )
    
  3. Medium density Normal screens HVGA 320x480 (160dpi):

    layout-mdpi (320 x 480 )
    layout-land-mdpi (480 x 320 )
    
  4. Medium density Large screens HVGA 320x480 (160dpi):

    layout-large-mdpi (320 x 480 )
    layout-large-land-mdpi (480 x 320)
    
  5. Galaxy Tab ( 240 dpi ):

    layout-large  (600 x 1024) 
    layout-large-land  (1024 x 600)
    
  6. High density Normal screens WVGA800 480x800 (x854) (240 dpi):

    layout-hdpi (480 x 800)
    layout-land-hdpi (800 x 480)
    
  7. Xoom (medium density large but 1280x800 res) (160 dpi):

    layout-xlarge (800 x 1280)
    layout-xlarge-land (1280 x 800)
    

Also add following code in .manifest file:

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

Solution 2:

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

You should probably read this:

Solution 3:

In addition to the traditional supports-screens parameters refer to the new Size Qualifiers launched in 3.2

Using new size qualifiers

The different resource configurations that you can specify based on the space available for your layout are summarized in table 2. These new qualifiers offer you more control over the specific screen sizes your application supports, compared to the traditional screen size groups (small, normal, large, and xlarge).

Table 2 enter image description here

To help you target some of your designs for different types of devices, here are some numbers for typical screen widths:

320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).

Using the size qualifiers from table 2, your application can switch between your different layout resources for handsets and tablets using any number you want for width and/or height. For example, if 600dp is the smallest available width supported by your tablet layout, you can provide these two sets of layouts:

res/layout/main_activity.xml           # For handsets
res/layout-sw600dp/main_activity.xml   # For tablets
<manifest ... >
    <supports-screens android:requiresSmallestWidthDp="600" />
    ...
</manifest>

Solution 4:

If you want to use only one layout xml that scales with the screen size you can use the sdp sdk.

Add the sdp sdk:

dependencies {
    compile 'com.intuit.sdp:sdp-android:1.0.2'
}

And you would be able to define a scalable TextView:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="A scalable text"
        android:textSize="@dimen/_12sdp" />