Meanings and usage of various folders in Android Projects

Source: Internet
Author: User

1. src: stores all *. java source programs.

2. gen: the path for saving the code file automatically generated by the ADT plug-in. R. java in the file will save all resource IDs.

3. assets: it can store large resource files of projects, such as images, music, and fonts.

4. res: All resource files in the project can be stored, such as images (*. png, *. jpg) and texts.

5. res/drawable-hdpi: saves high-resolution image Resources. You can use Resources. getDrawable (id) to obtain the resource type.

6. res/drawable-ldpi: saves low-resolution image Resources. You can use Resources. getDrawable (id) to obtain the resource type.

7. res/drawable-mdpi: saves medium-resolution image Resources. You can use Resources. getDrawable (id) to obtain the resource type.

8. res/layout: stores all layout files. It is mainly used to arrange different display components and read this configuration in the Android program.

9. res/values: stores the information of some resource files for reading text resources. There are some agreed file names in this folder:

. Attrs. xml: custom attribute value: For details, refer to http://blog.csdn.net/jiangwei0910410003/article/details/17006087. arrays. xml: defining array data;

Definition:

First Second Third Fourth

Read in code:

Resources r = this. getResources (); String [] ary = r. getStringArray (R. array. MyArray );

· Colors. xml: defines the color data. · dimens. xml: defines the scale. Resources can be used. getDimension () gets these resources; · strings. xml: defines strings. Resources. getString () or Resources. getText () method to obtain these resources; · styles. xml: defines the display style file;

10. res/raw: Customize the directory where some native files are located, such as music, video, and other file formats. Store any file that is directly copied to the device. They do not need to be compiled and are added to the compressed files generated by your application compilation. To use these Resources, you can call Resources. openRawResource (). The parameter can also be used as the resource ID, that is, R. raw.Somefilename, Resources. getRawResource () method to obtain these Resources.

11. res/xml: a user-defined XML file. All files are compiled into the application when the program is running. You can use the Resources. getXML () method to obtain them when the program is running.

12. res/anim: used to define animation objects. Stores XML files that define tweened animation or frameby frame animation. (This directory can also store XML files defining property animations, but it is best to store them separately)

13. res/animator: stores XML files that define propertyanimations (new animation framework of android 3.0 ).

14. res/color/: stores the XML file that defines the ColorState List Resource.

15. res/drawable/: stores XML files that define the ColorState List Resource.

16. res/menu/: stores XML files that define Application menu resources. Correct file creation method: new Folder, name menu, new Other -- Android -- XML, select menu type, enter name, and click OK. The menu resource file must be placed in the res/menu directory. The menu resource file must be used. Label as the root node. Besides In addition, there are two other labels used to set menu items and groups. The two labels are And .
Note:
Details about the content in the res/color and res/drawable files are as follows:
First, let's talk about the color folder. in this folder, there are color_selector.xml and other files, mainly used for the selector of the background color, such as the textColor attribute in TextView. Click to change the font color in TextView, the color_selector.xml file in this file is defined as follows:
 
 
  
      
      
      
  
 
The main attribute is that android: color references different color values, which are defined in the values/color. xml file, such:
 
     
  
   #000000
      
  
   #ffffff
  
 
At the same time, we can also find that the android: drawable attribute is not found in color_selector.xml. I don't know what Android determines when the android: drawable attribute is available and when the android: color attribute is available.
Next, let's take a look at the files in the res/drawable folder. The files in this folder, drawable_selector.xml, are mainly used for background images. android: background in the Button, click to change the background, and define the drawable_selecor.xml file:
 
 
  
      
      
      
      
      
      
  
 
Info_collect_btn_normal_bg and info_collect_btn_pressed_bg are image resources in the drawableXX folder.
At the same time, we also found that there is no android: color Attribute in drawable_selector.xml. Combined with the color_selector.xml above, there is no android: drawable attribute, knowing that Android should be determined based on folders, files in the color folder have the android: color attribute, and files in the drawable folder have the android: drawable attribute.
At the same time, it should be noted that files referenced by properties such as textColor and background cannot be referenced in disorder. For example, textColor references drawable_selector.xml, and if the background references color_selector.xml, an error is reported. So pay attention to use.
But now there is a problem: If the Button is to be clicked to change to green and not to red, what should we do?
First of all, you must use the background Property --> and you must use the drawable_selector.xml file to reference it. Therefore, in the drawable_selector _. in xml, change android: drawable = "@ drawable/info_collect_btn_normal_bg" to android: drawable = "@ color/not_pressed". The possible misunderstanding here is that android: drawable can only reference drawable resources, but it turns out that this misunderstanding is superfluous! For more information about the principles, see attr.

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.