Recipe Specifying Alternate Resources

The resources described in the previous section provide a generic configuration that Android can use by default. The developer has the ability to specify different values for specific configurations distinguished by various qualifiers.

To support multiple languages, the strings can be translated and used in different language values directories. For example,American English, British English, French, simplified Chinese (used in mainland China), traditional Chinese (used in Taiwan), and German strings are added using:

res/values-en-rUS/strings.xml res/values-en-rGB/strings.xml res/values-fr/strings.xml res/values-zh-rCN/strings.xml res/values-zh-rTW/strings.xml res/values-de/strings.xml

Not all strings need to be redefined in these files.Any missing strings from the selected language file fall back to the default res/values/strings.xml file, which should contain a complete set of all strings used in the application. If any drawables contain text and require a language-specific form, a similar directory structure should also apply to them (such as res/drawables-zh-hdpi/).

To support multiple screen pixel densities, the drawables and raw resources (as needed) can be scaled and used in different dots per inch (dpi) value directories. For example, an image file can belong to each of the following directories:

res/drawable-ldpi/ res/drawable-mdpi/ res/drawable-hdpi/ res/drawable-nodpi/

The low-, medium-, and high-density screens are defined as 120dpi, 160dpi, and 240dpi. Not all dpi choices need to be populated. At run-time, Android determines the closest available drawables and scales them appropriately.The nodpi choice can be used with bitmap images to prevent them from being scaled. In case both a language and dpi choice are specified, the directory can contain both qualifiers: drawable-en-rUS-mdpi/.

The various types of screens available for Android devices are discussed in Chapter 1, "Overview of Android." It is often useful to define separate XML layouts for the different screen types.The most often used qualifiers are

■ Portrait and landscape screen orientations: -port and -land

■ Regular (QVGA, HVGA, and VGA) and wide aspect ratios (WQVGA, FWVGA, and WVGA): -notlong and -long

■ Small (up to 3.0-inch diagonal), normal (up to 4.5-inch diagonal), and large (above 4.5-inch diagonal) screen sizes: -small, -normal, and -large

If screen orientation or aspect ratio are not defined, the Android system auto-scales the UI for the screen (although not always elegantly). However, if layouts for different screens are defined, a special element should be added to the Android Manifest XML file at the application element level to ensure proper support:

<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:resizable="true" android:anyDensity="true" />

Note that if android:minSdkVersion or android:targetSdkVersion is "3" (Android 1.5), then by default only android:normalScreens (the screen for the G1) is set to "true."Therefore, it is useful to explicitly declare the supports-screens element for the application so more recent phones have a properly scaled UI.

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook

Post a comment