Friday, February 22, 2013

How To Create Screen Size Independent Android Applications


How To Create Screen Size Independent Android Applications

How To Create Screen Size Independent Android Applications

 

Screen Sizes: large, normal, small
Density: high (hdpi), medium (mdpi), and low (ldpi).
Here are some of the techniques we can use to create a screen-size independent application

Low density: 120dpi; Skin: QVGA (320px*240px).
Medium density: 160dpi; Skin: HVGA (480px*320px).
High density: 240dpi; Skin: WGVA800 (800px*480px).

 

Resources folders

So, thinking a bit about screen elements, sizes, densities... we can arrive at the conclusion that the size of the screen affects the views, and the layouts we create, and the density of the screen affects the images we set in the layout.
One of the things we can do (there are many) is create layouts, views and images for every specific size and density. So, the resources directory could be something like:
res/layout/layout.xml
res/layout-small/layout.xml
res/layout-large/layout.xml
res/drawable-ldpi/icon.png
res/drawable-hdpi/icon.png 
 
 Like.


This way, in the “layout” directory, we put the layouts that are going to fit in a “normal” screen size, “layout-small” stores the same layouts but modified so they display on small screens properly. The same process is done in the “drawable” folders. In the “drawable-ldpi” and “drawable-hdpi” folders we store the images we use in our application, changing its density.

And after creating folder your file display look like ,

 For Small Layout folder layout display like,



 For Medium Layout in Layout Folder display like,















For Large Layout Folder display like,















Manifest

In Android , we have a new element in the manifest, the  tag. With this tag we can say how many screen sizes our application supports. android:smallScreens,android:normalScreensandroid:largeScreens and android:anyDensity.
This is a piece of the manifest:
 
android:largeScreens="false"
android:normalScreens="true"
android:smallScreens="true" 
android:xlargeScreens="true"
android:anyDensity="true" />



After going through all the resources we can use in our application to create the most “screen-size” independent.





for each screen resolution you can do following things,

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)

No comments:

Post a Comment