Application resources, slices, and strings should always be placed outside the code so that they can be maintained independently. When resources are put externally, you can also provide optional resources that support special device configurations, such as different languages or screen sizes. As Android supports more and more devices with different configurations, this feature of code and resource separation becomes increasingly important. To provide compatibility with different configurations, resources must be organized into the Res/directory of the project, and different types of configuration resources must be grouped using subdirectories.
For any type of resources, you can specify default resources and multiple optional resources for the application:
1. The default resource is the resource that is used when the device configuration is irrelevant or when there are no optional resources that match the current configuration.
2. Optional resources are the resources used to configure specific devices. For special configurations, you must specify a Resource Group and append an appropriate configuration qualifier to the directory name.
For example, if the default UI layout is saved in the Res/layout/directory, you can specify different la s for a horizontal screen and save them in the Res/Layout-land/directory. By matching the current configuration of the device with the Resource Directory, android can automatically apply suitable resources.
Figure 1 shows how the system applies the same layout to two different devices when there are no available resources. Figure 2 demonstrates the effect of an application when an optional layout resource is added to the screen device.
Figure 1. Two different devices with the default layout (no available layout resources)
Figure 2. Use different layout resources for different screen sizes for two different devices.