Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout files naming conventions?

What are some layout file naming conventions people have come up with.

I haven't found anything online, but thought about using the following convention.

What does everyone think?

 - activity_*   - dialog_*  - list_item_* 

That's all I have worked with so far.

Also, what about the naming of the activity against its layout? For example:

-> res     -> layout         -> activity_about_us.xml -> src     -> activity         -> AboutUs.java 
like image 724
Salsero69 Avatar asked Apr 07 '11 13:04

Salsero69


People also ask

How do you name a layout?

On the View tab, click Slide Master. In the left pane that contains the slide master and layout thumbnails, right-click the layout thumbnail that you want to rename, and then click Rename Layout. In the Rename Layout box, type the new name of the layout, and then click Rename.

What is a naming convention for files and folders?

A File Naming Convention (FNC) is a framework for naming your files in a way that describes what they contain and how they relate to other files. Developing an FNC is done through identifying the key elements of the project, the important differences and commonalities between your files.


2 Answers

Strangely enough, trying to google this question brings only this page as meaningful result... For the past half year I am using naming convention similar to yours but with shorter prefixes. For example: For activity that shows "About us" screen:

Class name: ActAboutUs. Prefixing class is kind of overkill but it clearly distinguishes activity classes from the others. Initially I used separate directory for all the activities (similar to your approach) but after some time I realized that for bigger apps may be it is better to group in directories by feature than by superclass (i.e. Activity). It is easier for me to work in single directory for example /src/settings/ when I work on Settings. That way all java files that I need are in a single dir so i don't have to wander around:

/src/settings/ActSettingsGlobal.java /src/settings/ActSettingsNet.java /src/settings/Settings.java /src/settings/SettingsDBAdapter.java /src/settings/etc... 

This approach also helps to split the work among different developers, i.e. each one is working in his own dir on separate feature so no stepping on each other's feet :-).

Some people preffer suffixes but I found them less useful. Prefixes help to group things alphabetically like in the example above: Act* prefix is sorted first so all activities are conveniently at the top.

I am even considering of using Act_ as a prefix which is more readable although it is in conflict with java naming conventions...

Layout filename: act_about_us.xml. In res/layout/ we don't have the "luxury" of subdirs which is quite unfortunate so the only way to group things is using appropriate prefix like act_, dlg_, etc...

String IDs: <string name="act_about_us_dlg_help1_title" ... string.xml is the place where we have most problems with duplicate names. It is very easy to create duplicates if naming convention like activity_element_item is not used. It adds a lot of additional typing but it saves you from a lot of confusion later on. For global (application wide) strings we use prefix "global_", for example global_btn_ok, global_msg_no_inet_conn. Usually we make one person responsible for all global_ strings so if someone needs new string or change he needs to sync with him in order to avoid creating a mess.

(now I am realizing that activity__element__item (two underscores) is more clear and readable than activity_element_item)

All in all I still can't get rid of the feeling that there is something wrong with my approach because I can't believe that google devs created such an inconvenient framework when it comes to working with files, IDs, names, etc...

like image 96
Ognyan Avatar answered Oct 01 '22 16:10

Ognyan


i think following naming convention should be follow

for activity

if our activity name is

DisplayListActivity 

then our layoutname should be

display_list_activity.xml 

for list items we can include category in list item layout name

country_list_item.xml 

and for dialogboxes their action can be included

delete_country_dialog.xml 
like image 35
Sunil Pandey Avatar answered Oct 01 '22 17:10

Sunil Pandey