For reference only, as long as the formation of a unified, see the amount of knowledge of its meaning can be
That is, the level of wages and your code quality proportional to the good habit of it!!
A Layout naming
1. Contentview Name: activity_ function module. xml
For example:activity_main.xml, Activity_more.xml
2. Dialog name: Dialog_ description. xml
Example:dlg_hint.xml
2. Popupwindow Name: ppw_ description. xml
Example:PPW _info.xml
3. List item naming listitem_ description. xml
Example:listitem_city.xml
4. Contains items: Include_ module. xml
For example:include_head.xml, Include_bottom.xml
(ii) Image naming
1. Static picture prefix _ module, Prefix _ module _ description
For example:bg_main.png, Ic_main_search.png
2. Dynamic Picture Prefix _ module _ description _ Status, Prefix _ description _ state
For example:btn_film_buy_n.png, Btn_film_buy_p.png, Btn_back_n.png
If there are multiple forms such as buttons, etc. except as btn_film_buy.xml (selector)
(c) ID name (to be adjusted?? )
The name of the ID in the XML, it is suggested to be named directly by meaning, without using the above complex positioning, because Findviewbyid only find in a specified layout. or value to establish the unified management of ID files (compatibility is not good)
The original author commonly used: android:id= "@id/tv_name" android:id= "@id/listv", android:id= "@id/tv_head_title"
Personal habits:android:id= "@id/tvname" android:id= "@id/listvname", android:id= "@id/tvheadtitle", Then the naming and ID names in class are consistent
(iv) string naming
Better not with title, dialog, button and other things related, directly with the same English meaning can be, if the following:
<string name= "OK" > OK </string>
<string name= "Welcome_to_use" > Welcome </string>
To cite some bad examples, the following <string name= "MENU_OK" > OK </string>
(v) Control naming
Control abbreviation _ Description
For example:TextView tv_name, Button btn_buy, linearlayout llyt_body;
(vi) class naming
Function module Activity.class function Module Service.class
such as:MainActivity.classHuaFuBaoActivity.classAppUpgradeService.class
Resource abbreviation Description
|
Prefix |
Description |
|
IC--icon |
Icons used primarily for layouts and sub-layouts |
|
Bg--background |
Used primarily for layouts and sub-layout backgrounds |
|
Di--divider |
Mainly used for dividing lines, including not only in the ListView but also in the normal layout |
|
Sl--selector |
Mainly used for a view of a variety of States, ListView button, etc. |
|
Cl--color |
Mainly used for color values |
|
Bt--button |
Mainly used for the representation of the button, sometimes we will hesitate between the IC and BT, a simple distinction is the function view, if a view executes the back or confirm or cancel function, then the name should use BT |
|
Suffix |
Description |
|
Unit |
When using XML Tilemode to match images, the element image uses the suffix |
|
Nor |
The state of the picture, representing the normal state |
|
hl |
The state of the picture, which represents the highlighted state |
|
Press |
The state of the picture, which represents the pressed state |
|
Select |
The state of the picture, which represents its occupied view is selected |
|
Unselect |
The state of the picture, which represents the view it occupies is not selected |
Component Name Comparison table
|
Component Name |
Shorthand |
Component Name |
Shorthand |
|
Button |
Btn (BTN) |
RadioButton |
RBTN (RBTN) |
|
ImageButton |
IBTN (IBTN) |
TextView |
TV (TV) |
|
ImageView |
IV (IV) |
Listview |
LV (LV) |
|
ProgressBar |
Pbar (Pbar) |
EditText |
EDTV (ET) |
|
ScrollView |
SCLV (scly) |
CheckBox |
CHK (CHK) |
|
Relativelayout |
Rlyt (Rlyt) |
LinearLayout |
Llyt (Llyt) |
|
Tablelayout |
Tlyt (Tlyt) |
Absolutelayout |
Alyt (Alyt) |
|
Framelayout |
Flyt (Flyt) |
|
|
Sharing is a programmer's virtue
Article source, Http://blog.csdn.net/bondsui
android--Development Naming conventions