Description of the relationship between the r class and resource files of Android applications

Source: Internet
Author: User

1. Create a helloworld project using eclipse. Shows the creation method:

1. After the project is created, the directory structure is shown in:

 

Iii. Description of the relationship between the r class and the resource file

1. the static drawable class corresponds to the drawable-hdpi, drawable-ldpi, and drawable-mdpi folders in the res folder, the static constant names of each integer in the drawable class are the same as the image resource files in these three folders (excluding the extension). Resources with the same file name in these three folders correspond to the same integer variable, the Android system automatically selects appropriate image resources based on different screen resolutions.

2. The static class layout corresponds to the layout folder in the res folder. Each layout file in the layout folder has an integer static variable that is the same as the file name in the layyout class.

3. The static class string corresponds to the string resources in each XML file in the Res/values folder. The strings. xml file in is defined as follows:

<? XML version ="1.0"Encoding ="UTF-8"?>

<Resources>

<String name ="Hello"> Hello world, helloworld! </String>

<String name ="App_name"> Helloworld </string>

</Resources>

In the string class, each static constant name is the same as the name attribute value in the <string> element.

Iv. Extensions

1. Resource file and configuration file androidmanifest. xml

A. <Application> the Android: icon attribute in the element uses the icon.png image specified in the drawableresource folder as the startup icon of the android desktop through @ drawable/icon. Android: the label will reference the <string> element with the value of app_name in the XML file in the values resource folder by @ string/app_name, the <string> element value is used as the application name under the android desktop startup icon.

B. The Android: Label attribute in the <activity> element uses the @ string/app_name method to reference the <string> element value of app_name as the title of the activity.

2. Do not use uppercase letters to name all files in the res folder.

3. Do not try to modify the content in the r class. The Android development tool will automatically generate and maintain this static class.

4. When the activity is created, the setcontentview () method is called to set the layout to the activity.

5. there is no limit on the number of files in the drawable, layout, and values files. You can define multiple resource files as needed. Each file is appended to the drawable and layout files, in the drawable and layout static classes, a static variable of the same Integer type as the file name is automatically generated. Append an XML file to the values folder. The name attribute value of the <string> element in the file corresponds to a static integer constant with the same property value in the string static class.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.