Tuesday, November 1, 2011

Tip: Naming Resource Files

Android has a lot of resource files. These normally are XML files that have the <resource> root tag. The standard convention is to split resources out by type. The problem with this is these files tend to get very large and become unweildly to edit. A better way to organize them is by adding a category to the file name as well.

For example: strings_preferences.xml would contain all the strings that pertain to preferences while strings_application.xml will pertain to application strings that you might not want to localize.

Layouts sometimes become difficult to determine where they lie in the hierarchy. A good convention is to name layouts that are bound to an activity with the prefix activity_[activity name]. So MainActivity > activity_main.xml. Do this with fragments too: BuddyListFragment > fragment_buddylist.xml.

No comments:

Post a Comment