android – Design Layout For Multiple Screens-ThrowExceptions

Exception or error:

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 ?

How to solve:
        android:anyDensity="true" />

You should probably read this:


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 240×320 (120dpi):

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

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

    layout-mdpi (320 x 480 )
    layout-land-mdpi (480 x 320 )
  4. Medium density Large screens HVGA 320×480 (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 480×800 (x854) (240 dpi):

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

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

Also add following code in .manifest file:

    android:anyDensity="true" />


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" />


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 ''

And you would be able to define a scalable TextView:

        android:text="A scalable text"
        android:textSize="@dimen/_12sdp" />


if you are using android 1.6 then try this for different layout as i have used it:

  1. if width – height – density :- 320 – 480 – 160 then res/layout folder name:- (layout-medium-mdpi)
  2. if width – height – density :- 480 – 800 – 160 then res/layout folder name:- (layout-large-mdpi)
    or if width – height – density :- 480 800 240 then res/layout folder name:- (layout-medium-hdpi)

it works….

Leave a Reply

Your email address will not be published. Required fields are marked *