The Res for Android application architecture

Source: Internet
Author: User

Res/drawable specifically for PNG, JPG and other icon files. Use Getresources (). Getdrawable (resourceId) in your code to get the resources under this directory.

Res/layout is dedicated to XML interface files, XML interface files and HTML files, mainly used to display the user interface.

The res/values is designed to store the various types of data used by the application. Different types of data are stored in different files, as follows:

· Strings.xml defines strings and values, and uses getresources (). getString (ResourceId) or getresources (). GetText (RESOURCEID) to obtain resources in the activity. Its role is the same as the internationalized resource file in struts.

<? XML version= "1.0" encoding= "UTF-8" ?> < Resources >  <  name= "Hello">hello</string> </ Resources >

· Arrays.xml defines an array.

<?XML version= "1.0" encoding= "Utf-8"?><Resources>  <String-arrayname= "Colors">  <Item>Red</Item>  <Item>Yellow</Item>      <Item>Green</Item>      <Item>Blue</Item>    </String-array></Resources>

· Colors.xml defines the color and color string values that you can use in Activity getresources (). Getdrawable (ResourceId) and Getresources (). GetColor ( RESOURCEID) access to these resources. Examples are as follows:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 3 <Resources>4 5   <Colorname= "Contents_text">#ff0000</Color>6 7 </Resources>

· Dimens.xml define dimension Data and use Getresources () in activity. Getdimension (RESOURCEID) access to these resources

<? XML version= "1.0" encoding= "UTF-8" ?> < Resources >  <  name= "Key_height">50dip</dimen>  </resources>

· Styles.xml defines the style.

1 <?XML version= "1.0" encoding= "Utf-8"?>2 3 <Resources>4 5   <stylename= "Itcasttext"Parent= "@style/text">6 7   <Itemname= "Android:textsize">18sp</Item>8 9   <Itemname= "Android:textcolor">#0066FF</Item>Ten  One   </style> A  - </Resources>

res/anim/stores XML files that define animations.

Res/xml/uses Getresources (). GetXML () in the activity to read the XML resource file under this directory.

res/raw/This directory is used to store the original files used by the app, such as sound files. When compiling the software, the data is not compiled and is added directly to the program installation package. In order to use these resources in your program, you can call Getresources (). Openrawresource (ID), parameter ID: r.raw.somefilename.

The Res for Android application architecture

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.