Multiple Screen Support in Android

multiple screen support in android

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

You have to add different folder for different layout in res folder --> hdpi,mdpi,ldpi and for large screens you xhdpi(for Tablet) and large-hdpi or xlarge (for NXzoom). Also set Images and text size different in different layout as per screensize...

Creating multi-screen support app android

Try out like:

  • layout-sw320dp
  • layout-sw480dp
  • layout-sw600dp
  • layout-sw720dp

instead of

  • layout-small,
  • layout-large etc...

How to support different screen size in android

For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens.

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

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

The following code in the Manifest supports all dpis.

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

And also check out my SO answer.

Supporting multiple screen sizes in Android by using multiple layouts

Android provides a very good way to support multiple screen sizes. It's called weights. You should use LinearLayout weights and check out your Graphical View to figure out how you want to resize.

Completely avoid:

  1. Calculating your resolutions and screen sizes. You will end up in a mess.
  2. Multiple layouts across dpi's.

Trust me, all the apps I have developed until now (12) have been done using weights with 1 layout file across all platforms. It works, and works like wonder.

Edit:

I also never use more than 5dp for padding and 10dp for margins. This way I keep the code clean and Android weights take care of my free space.

For more about weights, check out this question. It is really well explained to start with.

Edit Again:

Think about it. You are assuming dp to be the "same" in terms of physical mm (millimeters) for all phones. But it is not. In fact X and Y 1 dp may mean something different in "mm". dp is "not" consistent. Be careful when using code like 100dp and setting hardcoded widths and heights. And even worse, multiple layout files. You will get into a lot of code maintenance nightmares with those.



Related Topics



Leave a reply



Submit