Preface
This chapter is the Framework Topics/Application Resources Chapter of the Android developer guide, version is Android 3.2 r1, translated from: "CodeGuy", welcome to his blog: "http://www.cnblogs.com/CodeGuy ", thanks again for "CodeGuy "! We look forward to your participation in translation of Android related information, contact me over140@gmail.com.
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog Garden: http://www.cnblogs.com/
Android Chinese translation group: http://goo.gl/6vJQl
Application Resources
Translator's signature: CodeGuy
Link: http://www.cnblogs.com/CodeGuy/
Version: Android 3.2 r1
Original
Http://developer.android.com/guide/topics/resources/index.html
When you write a program, you should get used to the resources required by some programs, such as examples and strings, which are separated and independently stored outside your program code, in this way, you can maintain these resource files independently. The resource file is independent of the Code, which allows you to provide more optional resources for the program to support some special device configurations, such as different languages and different screen sizes. As more and more Android devices start to support different configurations, this becomes more and more important. To make these Android devices compatible with various configurations, you must organize the res/directory under your project and manage resources by group based on the type and configuration.
For any type of resources, you can specify default and multiple optional resources for your program:
* The default (default) resources should be those that can be used when the device configuration is ignored or when there are no other alternative resources that can match the current configuration.
* Alternative resources are the resources you set for specific configurations. A specific configuration corresponds to a group of specific resources, and then adds an appropriate configuration qualifier to the resource folder as the name.
(Note: a specific set of resources is a resource folder under your project directory. The layout folder res/layout is used)
For example, if your default UI layout is saved in the res/layout directory, you may need to set another UI layout to be saved in the res/layout-land/directory, it is used when your screen is landscape. Android automatically calls an appropriate resource by matching the current configuration information of the device to the name in your resource file directory.
Figure 1. Both devices use default Resources
Figure 2. Two different device configurations, one with alternative resources
Figure 1 shows how a set of default resources of an application are applied to different device configurations without any available alternative resources. Figure 2 shows that the same application has a set of alternative resources and each resource is limited to one device configuration, the two device configurations use different resources.
The above information only describes how application resources are applied on Android. The following documents provide a complete guide on how to organize and manage resources in your application, how to specify alternative resources, and how to use them in your program:
Providing Resources
This document describes what resource files you can use in your application, where these resource files are stored separately, and how to create Replaceable Resources for specific device configurations.
Accessing Resources
This document describes how to use the resources you provide, or how to reference resource files through your program code or from other XML type resource files.
Handling Runtime Changes
This document describes how to manage configurations when the Activity is running.
Localization
This document provides a bottom-up guidance on how to use replaceable resource files to initialize your application. Although this is only an alternative resource for a specific purpose, however, this is very important to attract more users.
Resource Types
This document describes various resource types that you can reference and describes the XML elements, attributes, and syntax of resources. For example, this reference will show you how to create a resource for the app's menus, images, colors, animations, and so on.