Resource management for Android

Source: Internet
Author: User

One, resource naming
Resource naming conforms to Java variable naming conventions
The file name or variable name of a homogeneous resource cannot be duplicated
ADT does not consider the extension name of the resource file when generating the ID
So you can't have the same file name, expand the name of different files

Second, access to resources
A,@[package]type/name
@ is the type of resource reference, package is the name of the bundle where the resource resides
Type resource types, allowable values are: Layout,value,drawable,string,color,menu,raw and XML, etc.
b, referencing system resources
@android: Type/name
Android:textcolor= "@android: color/opaque_red"
Resource access in the C,r.java
R,type.name
You can also add the package name to Android in front of R
Third, common types of resource access
1) String
Visit: @string/name
There is a special symbolic need to use "" and use the escape character
If you need to include dynamic parameters in a string resource, you need to use "%* $s" as a placeholder for the parameter, where * represents the number of the parameter
Reference timing requires the format method of string
2) Dimension
Dimension used to define the size and dimensions of a component
The file in the XML is declared in the following way:
<resources>
<dimen name= "name" > Size </dimen>
</resources>
Access style and layout are similar
3) drawable
The drawable resource is an abstraction of the drawing object to draw, and the drawing object is obtained by getdrawable (int id)
Several major drawable images:
Bitmap: A file with a Bitmap image
Nine-patch: A PNG file with a scaling area that can be based on content scaling objects
StateList: An XML file that references different bitmap objects for different states
Ps:android specifically defines a resource bit nine_patch image, which can be scaled automatically as a background, thus greatly saving memory

4) Color
Defined in a similar way
5) Shape
Used to define a drawing object
6) etc.

Resource management for Android

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.