Organize Resources

You should place each type of resource in a specific subdirectory of your project’s res/ directory. For example, here’s the file hierarchy for a simple project


MyProject/src/MyActivity.java
<strong>res/</strong> drawable/ icon.png 
layout/ activity_main.xml info.xml 
values/ strings.xml

The res/ directory contains all the resources in various subdirectories. Here we have an image resource, two layout resources, and a string resource file. Following table gives a detail about the resource directories supported inside project res/ directory.

Directory Resource Type
anim/ XML files that define property animations. They are saved in res/anim/ folder and
accessed from the R.anim class.
color/ XML files that define a state list of colors. They are saved in res/color/ and accessed
from the R.color class.
Image files like .png, .jpg, .gif or XML files that are compiled into bitmaps, state lists,
drawable/ shapes, animation drawables. They are saved in res/drawable/ and accessed from
the R.drawable class.
layout/ XML files that define a user interface layout. They are saved in res/layout/ and
accessed from the R.layout class.
menu/ XML files that define application menus, such as an Options Menu, Context Menu,
or Sub Menu. They are saved in res/menu/ and accessed from theR.menu class.
Arbitrary files to save in their raw form. You need to
raw/ callResources.openRawResource() with the resource ID, which is R.raw.filename to
open such raw files.
XML files that contain simple values, such as strings, integers, and colors. For
example, here are some filename conventions for resources you can create in this
directory:
arrays.xml for resource arrays, and accessed from the R.array class.
values/ integers.xml for resource integers, and accessed from the R.integerclass.
bools.xml for resource boolean, and accessed from the R.bool class.
colors.xml for color values, and accessed from the R.color class.
dimens.xml for dimension values, and accessed from the R.dimen class.
strings.xml for string values, and accessed from the R.string class.
styles.xml for styles, and accessed from the R.style class.
xml/ Arbitrary XML files that can be read at runtime by calling Resources.getXML(). You
can save various configuration files here which will be used at run time.
It's only fair to share...Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someoneBuffer this pageDigg thisFlattr the authorShare on StumbleUponPin on PinterestShare on YummlyShare on VKShare on RedditPrint this pageShare on Tumblr
Related Posts

7 Comments

  1. Bill May 21, 2015 Reply
  2. Bridget May 25, 2015 Reply
  3. Karoline May 27, 2015 Reply
  4. Galen May 29, 2015 Reply
  5. BerryNBrereton June 10, 2015 Reply
  6. NoeliaGBrevik June 13, 2015 Reply

Add a Comment

Your email address will not be published. Required fields are marked *