Thursday, 10 October 2013

Supporting Multiple Screen in Android

When you developing an android application, is it support in multiple screens?

This is really a Good question, When you developing an application, is it support in different screens i.e tablet,different sizes mobile and all.When you developing an application, he system handles most of the work to render your application properly on each screen configuration by scaling layouts to fit the screen size/density and scaling bitmap drawables for the screen density, as appropriate. To handle different screen configuration, you also have some ways as well:
1.    Explicitly declare in the manifest which screen sizes your application supports.
2.    Provide different layouts for different screen sizes.
3.    Provide different bitmap drawables for different screen densities.

Explicitly declare in the manifest which screen sizes your application supports:
When you developing an application, you can explicitely declare your screen size that your application will support. For that you need to add  <supports-screens>  in your android manifest file. In this <supports-screens> contains some attributes, you need spicify the value.
<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"]
Provide different layouts for different screen sizes:
By default, Android resizes your application layout to fit the current device screen. In most cases, this works fine. In other cases, your UI might not look as good and might need adjustments for different screen sizes. For example, on a larger screen, you might want to adjust the position and size of some elements to take advantage of the additional screen space, or on a smaller screen, you might need to adjust sizes so that everything can fit on the screen.
The configuration qualifiers you can use to provide size-specific resources are small, normal, large, andxlarge. For example, layouts for an extra large screen should go in layout-xlarge/.
Beginning with Android 3.2 (API level 13), the above size groups are deprecated and you should instead use the sw<N>dp configuration qualifier to define the smallest available width required by your layout resources. For example, if your multi-pane tablet layout requires at least 600dp of screen width, you should place it inlayout-sw600dp/.

Provide different bitmap drawables for different screen densities
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.
The configuration qualifiers you can use for density-specific resources are ldpi (low), mdpi (medium), hdpi(high), and xhdpi (extra high). For example, bitmaps for high-density screens should go in drawable-hdpi/.

For example, 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 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

No comments:

Post a Comment