Pages

Friday, July 26, 2013

Supporting Different Android Devices

1. Supporting Different Screens:

Screens come in four sizes: small, normal, large, xlarge. The current devices support four densities: low (ldpi), medium (mdpi), high (hdpi), extra high (xhdpi).

Corresponding folders in the project for different screen sizes are depicted via the following hierarchy.

MyProject/
    res/
        layout/              # default (portrait)
            main.xml
        layout-land/         # landscape
            main.xml
        layout-large/        # large (portrait)
            main.xml
        layout-large-land/   # large landscape

            main.xml

The generalized density buckets are: low, medium, high and extra-high density. Generate image for each density and use the following Google recommended scaling:
  • xhdpi: 2.0
  • hdpi: 1.5
  • mdpi: 1.0 (baseline)
  • ldpi: 0.75

2. Supporting Different Platform Versions:

Target the application for latest version and support almost 90% of the devices.

Specify Minimum and Target API Levels

In the AndroidManifest.xml file, the following attributes for the uses-sdk element are important.
minSdkVersion: lowest API level to keep the app compatible with.
targetSdkVersion: use the latest android version here.

Check System Version at Runtime

Use the Build constant class to check for the API level being executed. 

Use Platform Styles and Themes

The built in styles and themes are important to give the application look and feel of the underlying operating system.