Supporting Multiple Screen Size - Android

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 size - Android

I just did something very similar. To stretch the app without creating new layouts I used dimensions set in XML

res/values/dimensions.xml
res/values-sw600dp/dimensions.xml -> 7+ inches
res/values-sw720dp/dimensions.xml -> 10+ inches

Dimensions are resources files:

<dimen name="default_padding">11dp</dimen>

You can increase the dimensions by about 30% in the 600 and 720 file.
Then simply used @dimen/default_padding in your layout and it will be scaled

Regarding images, either you make sure you have all your assets in all densities, or you set fixed size to you ImageView's and appropriate scaleType

Creating Same UI Supporting Different Screen Sizes?

Use SDP - a scalable size unit library for supporting different screens.

An android SDK that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens.
Here is the LINK

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

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