Raj
Raj

Reputation: 217

Multiple Screen Size support for android?

I am creating a simple layout in android with some customized buttons(not the ones android provides by default).The image appears proper on screen size 2.7 to 5.1. However buttons appear stretched on screen size 5.4 and greater (tried till screen size 7).I have made four same images named them similarly of different densities and placed them correspondingly in the folders ldpi,mdpi,hdpi,xhpi.I need to know whether i need to create different layouts for different screens?Or android picks up images automatically from the corresponding folders?Some body please guide me as i am new to android on this as i am struggling to create layouts targeting android mobile devices.

Upvotes: 0

Views: 5714

Answers (5)

Nezam
Nezam

Reputation: 4132

You should adopt writing different layouts xml for different screen sizes and put them into the res folder.

For approaching different densities due to Android versions one can go about like this

res/layout/mylayout.xml       # Default layouts
res/layout-v4/mylayout.xml    # Android 1.6 layouts
res/layout-v11/mylayout.xml   # Android 3.0 layouts

while for different screen sizes you need some layouts like these:

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)

More info about these different layouts (qualifiers) can be found here.

Go through this question and its answers too.

Note: always use relative layouts when handling different screen sizes; it's a plus.

Edit

To get to know more about resource qualifiers these links are good.

Upvotes: 3

Avadhani Y
Avadhani Y

Reputation: 7626

No need of defining different layout folders(layout-land, layout-large, layout-small) if u designed layouts consistently. The Android OS will take care of that(regarding images display). Only thing you have to do is add the <support-screens> in your manifest and below is the <support-screens>:

 <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:compatibleWidthLimitDp="integer"
              android:largestWidthLimitDp="integer"/>

Tips for Creating consistent layouts:

  1. Dont hard-code any layout parameters such as width,height,etc..
  2. Dont use "px".Use "sp" for Text Size and "dp" for layout-width, layout-height etc.
  3. Make use of RelativeLayout and LinearLayout and dont use AbsoluteLayout as it is deprecated.
  4. Use ScrollView wherever required for layouts as it supports for a singleView.

For more information check the Android Developer documents of Support Multiple Screens.

Upvotes: 4

NagarjunaReddy
NagarjunaReddy

Reputation: 8645

use this in manifest.xml

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

How to solve Android screen size for different mobile devices?

http://developer.android.com/guide/practices/screens_support.html

Upvotes: 1

kumar_android
kumar_android

Reputation: 2263

If you have different pictures in all the density folder, android will automatically take from the corresponding folder. make sure that you are using nine-patch image in the density folder.

Have a look of Supporting Multiple Screens in Android

Upvotes: 1

Usama Sarwar
Usama Sarwar

Reputation: 9020

The following link will help you understanding Supporting multiple screens in android: http://developer.android.com/guide/practices/screens_support.html

Upvotes: 1

Related Questions