Resources and Configuration

Description

Android resources generalize configuration idea to any configuration of the device. Language is one configuration choice.

Android allows you to pick different sets of layouts based on layout mode for the same resource ID.

Android does this by using different directories for each configuration.

Example

When using the smart phone we can use it vertically or horizontally. The vertical mode is called the portrait mode and the horizontal mode the landscape mode.

The following three main_layout.xml files are all for layout. Android will load the corresponding files.


\res\layout\main_layout.xml
\res\layout-port\main_layout.xml
\res\layout-land\main_layout.xml

Note

Even though there are three separate layout files here, they all generate only one layout ID in R.java.

This ID looks as follows:


R.layout.main_layout

When you retrieve the layout corresponding to this layout ID, you get the appropriate layout suitable for that device layout.

The directory extensions -port and -land are called configuration qualifiers.

These qualifiers are case insensitive and separated from the resource directory name with a hyphen (-).

Resources in these configuration qualifier directories are called alternate resources.

The resources in resource directories without the configuration qualifiers are called default resources.





















Home »
  Android »
    Android Basics »




Hello Android
Resources
Activity
Calendar
Camera
Contact
Content Provider
Database
Hardware
Intent
Location
Media
Network
Notification
Preference
Sensor
Service
SMS