Description and role of folders in Android projects

Source: Internet
Author: User

(Transferred from: http://blog.csdn.net/goodshot/article/details/11529731)

the role of folders in Android projects

1. SRC: Store all the *.java source programs.

2. Gen: Save the path for the automatically generated code file for the ADT plugin, and the R.java will save all resource IDs.

3. Assets: Can be stored in the project some large resource files, such as: pictures, music, fonts and so on.

4. Res: can store all the resource files in the project, for example: Pictures (*.png, *.jpg), text, etc.

5. RES\DRAWABLE-HDPI: Save a high-resolution picture resource, you can use Resources.getdrawable (ID) to get the resource type.

6. RES\DRAWABLE-LDPI: Save a low-resolution picture resource, you can use Resources.getdrawable (ID) to get the resource type.

7. RES\DRAWABLE-MDPI: Save the medium resolution picture resource, you can use Resources.getdrawable (ID) to get the resource type.

8. Res\layout: Store all layout files, mainly for arranging different display components, to read this configuration in the Android program.

9. Res\values: To store some resource file information for reading text resources, in this folder there are some agreed file names:
· Arrays.xml: Define array data;
· Colors.xml: Defines the data that represents the color;
· Dimens.xml: Define scales that can be used to obtain these resources using resources.getdimension ();
· Strings.xml: Defines a string that can be obtained using the resources.getstring () or Resources.gettext () method;
· Styles.xml: Defines the displayed style file;

10.res\raw: Custom native files in the same directory, such as music, video and other file formats, Resources.getrawresource () method can obtain these resources.

Res\xml: User-defined XML files, all files are compiled into the application while the program is running, and can be obtained using the Resources.getxml () method when the program is running.

Res\anim: Used to define animated objects;

Bin: The folder where the APK is generated.

Description

1. drawable and Layout cube resources, the project will automatically identify these resources, and then in the R file corresponding to each resource file generated an ID, you can directly in the code through the R.drawable.id or r.layout.id to invoke these resources.

        2. The resource system in asserts will not be automatically recognized, you need to read through the IO, you can usually place audio files or encrypted files and other system unrecognized files, of course, you may also put pictures and so on here, but the system does not automatically recognize these resources.
        3. R class and resource file Relationship description

1). Static class Drawable class corresponds to drawable-hdpi, drawable-ldpi, drawable-mdpi three folders in the Res folder, The static constant name for each integral type in the Drawable class is the same as the picture resource file in these three folders (without the extension), the same integer variable for the same file name in the three folders, and the Android system automatically chooses the appropriate picture resource based on the different screen resolutions.

2). The static class layout class corresponds to the layout folder in the Res folder, and each layout file in the Layout folder will have an integer static variable with the same file name in the layout class.

3). Static class string corresponds to the string resource in each XML file in the Res/values folder, as defined in the Strings.xml file in the following:

<?xml version="1.0" encoding="Utf-8"?>

<resources>

<string name="Hello"> Hello World, helloworld!</string>

<string name="App_name">HelloWorld</string>

</resources>

The string class uses the same name as the Name property in the <string> element for each static constant.

4. Extension instructions

1). resource file and manifest file Androidmanifest.xml

A. The Android:icon property in the <application> element references the icon.png image defined in the Drawable resource folder as the boot icon for the Android desktop by @drawable/icon; Android:label will refer to the values resource file in a way that @string/app_name

Add IDs Description : (From: http://blog.sina.com.cn/s/blog_ac843e3301014fbr.html)

We've seen the Ids.xml file before, but what does this file mean? Let's look at the description in the documentation:

First look at the example it gives: XML file saved atres/values/ids.xml: How to use: one:android:id= "@id/button_ok"Two: Button Btn=new button (context);btn. SetId (Context.getresources (). Getinteger (R.ID.BUTTON_OK));The written form of the red part is incorrect, we use Btn.setid directly (R.ID.BUTTON_OK); OK, If you use the red part, you will be presented with an error that cannot be found. Using both of these methods is possible, if we use ids.xml we have the following several benefits: 1. Naming is convenient, we can put some specific control first name, we use the time directly in our layout to set the ID, save a naming link. 2. When we write the code layout, when we set the ID, we need to use this method to name our control, it can be found in the R file to find the corresponding ID, and then to convert. Note: Each item in Ids.xml will also be generated into the R file, as the above Ids.xml will generate the following control in our R file: public static final class ID {public static final int        button_ok=0x7f080000; public static final int dialog_exit=0x7f080001; When we use it, no matter which way we set the ID, it's the same: Findviewbyid (R.ID.XXX);

Description and function of folders in Android project (GO)

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.