类型 | 规则 | 例子 | 备注 | ||
包名(只能使用小写字母和.) | 顶级包名 | 类型+公司/组织+项目 | org.aaa.bbb 其中org代表肥盈利性,aaa代表公司或组织,bbb代表项目 | ||
模块 | 类型+公司/组织+项目+模块 | org.aaa.bbb.usercenter usercenter代表用户中心这个模块 | |||
类名(大驼峰法且只用字母和数字) | 从android SDK中派生出来的子类 | 功能+父类类名的缩写/全称 | public class GoodsFragment extends YBaseFragment{} 其中Goods表示是商品页面,Fragment表示集成只android的Fragment类 | ||
与xml中include标签对应的可重用的/子布局的类 | 功能+Layout | GoodsSpecLayout,其中GoodsSpec表示该布局是商品规格, Layout是固定的后缀表示是该布局是一个可以被复用的子布局 | |||
bean包下的类 | 功能+Bean | ||||
service包下的类 | 统一只放服务的接口,并全部以Service为后缀 | public interface ConfigService {} | |||
service.impl包下的类 | 统一只放服务的具体实现类,并全部以ServiceImpl为后缀 | public class ConfigServiceImpl implements ConfigService {} | |||
变量 | 从view派生出来的ui控件 | 与xml中的id名称保持一致 | private TextView tvGoodsCate4Title;对应<TextViewandroid:id="@+id/tvGoodsCate4Title"/> | ||
非从view派生出来的ui控件 | 小驼峰法 | private String mGoodsId; | |||
函数 | 小驼峰法 | public void onCreate(Bundle savedInstanceState){} | |||
常量 | 固定为static final,不使用final static;只使用大写字母、数值和_ | private static final int GOODS_CATE_LEVEL3 = 3; | |||
资源(文件名称只能使用小写字母、数字和_) | anim | 具体使用该动画的页面的类名缩写+动画功能 | GoodsDetailActivity中显示商品评价记录布局的一个入场动画命gda_comment_in,其中gda是GoodsDetailActivity的缩写(所有单词的首字母组合),comment_in表示是评论记录的入场动画 | ||
drawable | 图片 | 图片的特征 |
| ||
shape | shape+控件id的变种 | shape_tv_goods表示商品文本的背景 | |||
selector | selector+控件id的变种 | selector_tv_goods表示商品文本的背景 | |||
layout | 布局中控件的id | 使用小驼峰命名方式,控件类型缩写+功能 | <Button android:id="@+id/btnBack"/> 其中btn是Button的缩写,Back是代表该按钮的功能是返回 | ||
从android SDK中派生出来的子类 | 类名后缀前置 | GoodsDetailActivity类对应的布局命名为activity_goods_detail | |||
与xml中include标签对应的可重用的/子布局的类 | layout后缀前置 | GoodsSpecLayout类对应的布局命名为layout_goods_spec | |||
所有从dialog派生出来的子类 | dialog+功能 | 退出应用的dialog命名为dialog_exit_app | |||
ListView,GirdView等的项 | item+控件类型缩写+功能 | 商品评论列表中的项命名为item_lv_goods_comment | |||
values | strings | 具体使用该sting的页面的类名缩写+控件id变种+类型 | <string name="fpa_tv_new_psw_text">新密码:</string> <string name="fpa_et_new_psw_hint">请输入新密码</string> 其中fpa是页面ForgetPswActivity的缩写,tv和et是TextView和EditText控件的缩写, text和hint分别表示文本和提示文本 | ||
styles | 具体使用该sting的页面的类名缩写+控件id变种+类型 | <style name="pdgda_tv_num"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> </style> | |||
colors | 具体使用该sting的页面的类名缩写+控件id变种+类型 | <color name="gda_tv_num_bg">#5e5e5b5b</color> <color name="gda_tv_num_text">#5e5e5b5b</color> 其中gda是页面的缩写,tv_num控件id(tvNum)的变种,bg代表背景色,text代表文本色 | |||
dimens | 具体使用该sting的页面的类名缩写+控件id变种+类型 | <dimen name="gda_ll_order_record_right_w">440dp</dimen> 其中gda是页面的缩写,ll_order_record_right控件id(llOrderRecordRight)的变种,w代表宽度 | |||
注释 | 单行注释,主要用于描述代码逻辑 | 位于被注释代码的右边 | int goodsCateSize 6;//一级商品分类的数量(不包括默认额) | ||
多行注释,主要用于描述类的功能和其他基本信息、描述函数的功能、成员变量的用处 | 位于被注释代码的上边 | /** * 应用显示的高度 */ public static int DISPLAY_HEIGHT = -1; /** * 在电商端登录 * * @param context 发送请求的上下文 * @param handler 回调 */ public RequestHandle ShopLogin(Context context, BaseJsonHttpHandler handler){} /** * Description:登录的接口,使用持久化的cookies来保存登录状态 * User: Caizemingg(Email:Caizemingg@163.com) * Date: 2014-12-10 * Time: 19:11 * ModifyDescri: * ModifyDate: */ public interface AccountService {} |