2-9. Implementing Situation-Specific Layouts

Problem

Your application must be universal, running on different screen sizes and orientations. You need to provide different layout resources for each of these instances.

Solution

(API Level 4)

Build multiple layout files, and use resource qualifiers to let Android pick what’s appropriate. We will look at using resources to create layouts specific for different screen orientations and sizes. We will also explore using layout aliases to reduce duplication in cases where multiple configurations share the same layout.

How It Works

Orientation-Specific

In order to create different resources for an activity to use in portrait vs. landscape orientations, use the following qualifiers:

  • resource-land ...

Get Android Recipes: A Problem-Solution Approach, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.