All Screens Great and Small

Supporting different screen sizes, resolutions, and pixel densities is important because you want your application to look its best on as many Android devices as possible. Unlike the iPhone, which has just one standard screen (OK, three, if you count the iPad and the iPhone 4), Android-powered devices come in all shapes and sizes.

Android will try to scale your user interface to fit the device, but it doesn't always do a great job of it. The only way to tell is through, you guessed it, testing. Use the emulator skins recommended in Section 13.1, Gentlemen, Start Your Emulators, on page 257 to make sure your program works on the most common sizes. If you need to tweak the layouts or images for particular configurations, you can use suffixes in the resource directory names.

For example, you can put images for high-density displays in the res/ drawable-hdpi directory, medium density in res/drawable-mdpi, and low density in res/drawable-ldpi. All the examples do that for their program icons, which will be shown on the home screen. Graphics that are density-independent (that should not be scaled) go in the res/drawable-nodpi directory.

The following is a list of the valid directory name qualifiers, in order of precedence:9


Mobile country code and optional mobile network code. I don't recommend using this. Two-letter language and optional two-letter region code (preceded by lowercase r). For example: fr, en-rUS, fr-rFR, es-rES. small, normal, large. long, notlong. port, land, square. ldpi, mdpi, hdpi, nodpi. notouch, stylus, finger. keysexposed, keyshidden, keyssoft. nokeys, qwerty, 12key. navexposed, navhidden. nonav, dpad, trackball, wheel. 320x240, 640x480, and so on (not recommended by Google but people use it anyway). ApI level supported by the device (preceded by lowercase "v"). For example: v3, v8.

To use more than one qualifier, just string them together with a hyphen (-) in between. For example, the res/drawable-fr-land-ldpi directory could contain pictures for low-density displays in landscape mode in French.

Note: In versions prior to 2.1, Android had bugs in how it matched these qualifiers. For advice on dealing with quirks like this, see Justin Mattson's Google I/O presentation.10



Language and region

Screen dimensions Wider/taller screens Screen orientation Screen pixel density Touchscreen type Keyboard available? Keyboard type Navigation available? Navigation type Screen dimensions

SDK version

0 0

Post a comment