A few lines of code to see the level of programmers - Android file naming convention

Note: A very brief and practical summary:

resource control naming

For reference only, as long as a unity is formed, you can see the meaning

The level of programmers is the most direct from the code specification. That is, the level of salary is directly proportional to the quality of your code, so develop good habits! !

(1) Layout naming

1. Contentview name: activity_function module.xml

For example: activity_main.xml, activity_more.xml

2. Dialog name: dialog_description.xml

       For example: dlg_hint.xml

2. PopupWindow naming: ppw_description.xml

       For example: ppw_info.xml

3. List item named listitem_description.xml

       For example: listitem_city.xml

4. Include: include_module.xml

       Example: include_head.xml, include_bottom.xml

 

(2) Image naming

1. Static image prefix_module, prefix_module_description

例如:bg_main.png、ic_main_search.png

2. Dynamic picture prefix_module_description_status, prefix_description_status

              例如:btn_film_buy_n.png、btn_film_buy_p.png、btn_back_n.png

       If there are multiple forms such as buttons, except for btn_film_buy.xml(selector)

 

(3) id naming (to be adjusted??)

The naming of the id in Xml, it is recommended to name it directly according to the meaning, and it is not necessary to use the above complex positioning, because findViewById is only found in a specified layout. Or create a unified management of the id file in the value (incompatibility is not good)

原文作者常用: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", and then the name in the class is consistent with the id name

(4) String naming

       It is best not to be related to title, dialog, button, etc., just use the same English meaning directly, if the following:

<string name="ok">确定</string>

<string name=" welcome_to_use">欢迎使用</string>

 

Give some bad examples, as follows <string name="menu_ok ">OK</string>

 

(5) Control naming

Control Abbreviation_Description

例如:TextViewtv_name、Button btn_buy、LinearLayoutllyt_body;

 

(6) Class naming

Function module Activity.class   Function module Service.class

如:MainActivity.class  HuaFuBaoActivity.classAppUpgradeService.class

 

资源缩写说明

 

 

前缀

说明

ic --icon

主要用于布局和子布局的图标

bg--background

主要用于布局和子布局的背景

di--divider

主要用于分隔线,不仅包括Listview中的还包括普通布局中的线

sl--selector

主要用于某一view多种状态,listview 按钮等

cl--color

主要用于颜色值

bt--button

主要用于按钮的表示,有时我们会在ic和bt之间犹豫,简单的区分即是功能视图,如果一个view执行的时back或者confirm或者cancel的功能,则命名上则应该使用bt

 

 

 

 

后缀

说明

unit

在使用xml的tilemode来配图片时,element图片使用此后缀

nor

图片的状态,代表普通状态

hl

图片的状态,代表高亮状态

press

图片的状态,代表按下状态

select

图片的状态,代表其所占的view被选中

unselect

图片的状态,代表其所占的view没有被选中

 

 

 

 

 

 

 

 

 

 

 

组件名称对照表

 

组件名称

简写

组件名称

简写

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)

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326769635&siteId=291194637