5.3.8. Supporting Different Screen Sizes and Resolutions

In Section 2.5.1 you learned that Android devices have various screen sizes, resolutions and pixel densities (dots per inch or DPI). You also learned that you typically provide images and other visual resources in multiple resolutions so Android can choose the best resource for a device’s pixel density. Similarly, in Section 2.8, you learned how to provide string resources for different languages and regions. Android uses resource folders with qualified names to choose the appropriate images based on a device’s pixel density and the correct language strings based on a device’s locale and region settings. This mechanism also can be used to select resources from any of the resource folders discussed in Section 5.3.7.

For this app’s MainActivity, you’ll use size and orientation qualifiers to determine which layout to use—one for portrait orientation on phones and tablets and another for landscape orientation only on tablets. To do this, you’ll define two MainActivity layouts:

activity_main.xml in the project’s res/layout folder is the default layout.

activity_main.xml in the project’s res/layout-large-land folder is used only on large devices (i.e., tablets) when the app is in landscape (land) orientation.

Qualified resource folder names have the format:

name-qualifiers

where qualifiers consists of one or more qualifiers separated by dashes (-). There are 18 types of qualifiers that you can add to resource folder names. We’ll explain other qualifiers as we use them throughout the book. For a complete description of all the res subfolder qualifiers and the rules for the order in which they must be defined in a folder’s name, visit:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.142.250