1. Android device configurations
1.1. Handling different Android devices
Android device comes in a variety of different configurations in the sense of size, screen pixel density, language settings, etc.
To provide the correct resources and setting for these different configurations, Android support the automatic selection of resources and the definition of the size of user interface components in a relative size format (device independent pixel).
1.2. Resource qualifiers
Android allows you to use resource qualifiers to specify that certain resources should only be used for a specific device configuration (e.g., orientation, resolution, languages). To provide different resource files, e.g., layouts for configurations described by a
qualifier selector, you should create a new sub-folder in the res folder using this qualifier, for example, layout-qualifier for layouts.
|Android selects the correct file automatically based on the current configuration.|
1.3. Important resource qualifiers
1.3.1. Using orientation as resource qualifier
Assume, for example, that you want to use a special layout for your activity in landscape mode and that the layout file is called activity_main.xml. In this case you create the res/layout-land folder and place the new layout file with the same name (activity_main.xml) in this folder.
1.3.2. Android version qualifiers
A typical selection you use in your application, is the selection based on Android version, which is based on the
-v[minimum API level] qualifier. For example, this way you can provide different styling and themes based on the Android API revision.
A typical example for using this qualifier is to define the styling based on the Android version.
1.3.3. Width and height related qualifiers
Another typical selection is the smallest available width selection or the available width selection. The smallest available width is the shortest of the screen’s available height and the available width is the actual width based on the orientation of the device.
The width selection can, for example, be used to provide different layouts based on the width of the device. This selection is based on
-sw[Number]dp (Smallest) or
-w[Number]dp qualifier, where [Number] stands for the number of device independent pixels. For example, a 7inch tablet typically has at least 600dp and you could provide layouts for it via the
1.3.4. More resource qualifiers
The other resource qualifiers are described on the following webpage.