|Handling Multiple Screen Size in Android|
Aug 13, 2012
About This Article
This article provides information about how to make Android application for multiple screen resolutions. Android application developers can use this article as reference to implement the application for multiple screens available from different vendors.
This article is intended for Android developers wishing to develop mobile applications. It assumes basic knowledge of Android and Java programming languages.
To find out more about Android, please refer to the Knowledge Base under Samsung Developers.
Android devices come in a variety of screen sizes and resolutions. Android dynamically scales and resizes application graphics to fit these different from factors, however this scaling isn’t perfect and may hurt user experience. A smartphone app that is run on a Tablet, for example, “blows up” the graphics in order to fill the larger screen, but if resolution of those graphics does not take different screen sizes into account, the result will not be appealing.
Developers can apply the following methods to maximize the user experience on a variety of devices. This document explains multi-screen handing on Android platform along with the overview of system supported utilities.
Default Things on App Installation
By default Android runs applications in "compatibility mode", scaling everything based on the actual screen size. For a 20px square PNG file on a device with high-density screen, it may scale PNG file up to 30px during image rendering making the image blurry.
Android blocks applications from running on devices with too small of a screen, hence QVGA devices will not downloads certain apps that require a larger screen. To avoid this, compile the application with the higher resolution graphics so that Android can fill the screen size properly, without relying on "compatibility mode".
Handing Screen Density
You can develop your application to maintains the physical size of the interface by using fill_parent and wrap_content values for android:layout_width and android:layout_height. This parameter does not specify size but adapts to the space available.
Bitmap scaling can result in blurry images. To prevent this, provide higher-resolution bitmaps for high-density screens and the system will use those instead of resizing the bitmap designed for medium-density screens.
Following are ways the Android system helps to achieve density independence:
Density Based Set:
To set labels for different layouts, dimensions or different screen density resources, use the following resource directories:
Supporting Multiple Screen Sizes
To set up support for multiple device sizes in Android, add the <support-screens> element into the AndroidManifest.xml file. This field specifies which screen size support and which do not. The developers who don't want to handle automatic "compatibility mode" can implement this attribute into the manifest file. Include <support-screens> attributes into the AndroidManifest.xml as shown the following code sample:
Finding Screen Layout Size
The Configuration object holds information related to screen size. It has a public field named screenLayout, which is a bitmask indicator which helps to find out the screen type. The following code sample shows how to find the screen size:
You can find out the device’s screen density in a similar fashion:
Adjusting Density on the Emulator
The Android SDK includes emulator skins which have their own default display sizes and densities. You can also modify the default size, density and resolution of an emulator skin to test any possible screen configuration. Adjusting the emulator density is as follows under the eclipse IDE:
Click on Launch -> AVD Manager -> Start
You are ready to adjust the emulator density.
Currently Android provides some individual tools that can help the developers at the initial stage of their projects development, in terms of designing and handling multiple screen size.
1. Android Asset Studio
The Android Assets Studio is a web-based tool which is still in beta version. It is used for generating drawable resources and other assets for Android applications.
The available assets supported are:
2. UI Prototyping Stencils
UI Prototyping Stencils is a GUI prototyping tool. It helps developers draw GUI prototyping that everyone can use.
The available assets supported are: