November 25, 2013

Naming convention for Android layout resources

Every time when I was creating new layout resource there was issue: how to name it?

We are always creating .xml layout for Activity, Fragment, Dialog and custom View:

item_details_fragment.xml
main_activity.xml
money_picker_dialog.xml
settings_activity.xml

Too long list of unorganized resources scares me every time.

I tried to use prefixes to group resources for different entities.

activity_main.xml
activity_settings.xml
dialog_money_picker.xml
fragment_item_details.xml

Now list looks quite good, but names are too long. So, after that I tried to use single letter as prefix:

a_main.xml
a_settings.xml
d_money_picker.xml
f_item_details.xml

Wow! It's that I want!

I'm not submitting a request to be a winner of Naming Files World Championship, but I want to share this simple technique and I hope it will help somebody.

Look at my project's list of resources - simple and intuitive:

a_ layout for Activity
d_ layout for Dialog
f_ layout for Fragment
t_ layout for Toast
v_ layout for View


No comments:

Post a Comment