Resource Qualifiers for Screen Size and Pixel Density

In Chapter 3 you were introduced to the Android resource framework. Using this framework you can create a parallel directory structure to store external resources for different host hardware configurations.

This section summarizes the folder-name qualifiers you can use to include alternative resources for different screen sizes, pixel densities, and aspect ratios.

> Screen size The size of the screen relative to a "standard" smartphone (such as the G1 or Droid).

> small A screen smaller than the standard 3.2"

> medium Typical smartphone screen size

> large A screen significantly larger than that of a typical smartphone, such as the screen of a tablet or netbook

> Pixel density Refers to the density of pixels on the display. Typically measured in dots per inch (dpi), this is calculated as a function of the physical screen size and resolution.

> ldpi Used to store low-density resources for screens with pixel density in the range of 100 to 140dpi

> mdpi Used for medium-density screens with 140 to 180dpi

> hdpi Used for high-density screens featuring 190 to 250dpi

> nodpi Used for resources that must not be scaled regardless of the host screen's density

> Aspect ratio The screen's aspect ratio is the ratio of its height to its width.

> long Used for screens that are significantly wider in landscape mode than those of standard smartphones (such as the G1)

> notlong Used for screens with a typical smartphone aspect ratio

Each of these qualifiers is independent and can be used independently, or in combination with each other, as shown in Listing 4-24.

Note that these qualifiers can also be used with the other resource folder qualifiers described in Chapter 3.

LISTING 4-24: Sample screen-based resource directory qualifiers

Available for download on res/layout-small-long/ // Layouts for small, long screens, res/layout-large/ // Layouts for large screens, res/drawable-hdpi/ // Drawables for high density screens.

Was this article helpful?

0 0
Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide

Post a comment