Monday, October 1, 2012

Optimizing applications for different resolutions

The question of developing an application that supports a large number of screen resolutions always gets an edge from developers under Android. As the number of different devices has already exceeded 1,000. In this article I will talk about one of the ways to support different resolutions in the application.

What is used

At the heart of my method of optimization is such a characteristic screen as size. Now, the following qualifiers:
  • Small: used for resources with small screens (mostly 240x320);
  • Normal: used for resources with the normal screen (mostly 480x800);
  • Large: is used for resources with larger screens (mostly 600x1024 or tablet 7");
  • Xlarge: used for resources with very large screens (mostly 1280x800 and above or tablets from 9").
If it is possible to use the Nine-Patch image, it is best to use them.

Use

Font sizes and items we store in the resource file dimen.xml.
Font size:
<dimen name="txt_size_12">12sp</dimen>
Dimensions of the elements:
<dimen name="image_width_50">50dp</dimen>
For the way we use these dimensions in xml used qualifier @dimen.
For example:
android:textSize="@dimen/txt_size_12"
or
android:layout_width="@dimen/image_width_50"
Optimization method is to create and match sizes for different screens. You can use emulators with different resolutions. 

Restriction devices in Google Play

Visibility of your application for different screen sizes can be limited by using the following code in AndroidManifest:
<supports-screens android:smallScreens="true"
                  android:normalScreens="true"
                  android:largeScreens="true"
                  android:xlargeScreens="true"
                  android:anyDensity="true"/>
Related Links