首页 > 代码库 > Android研发规范

Android研发规范

<style></style><style>/* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:Cambria; mso-ascii-font-family:Cambria; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Cambria; mso-hansi-theme-font:minor-latin; mso-font-kerning:1.0pt;} table.MsoTableGrid {mso-style-name:网格型; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-priority:59; mso-style-unhide:no; border:solid windowtext 1.0pt; mso-border-alt:solid windowtext .5pt; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-border-insideh:.5pt solid windowtext; mso-border-insidev:.5pt solid windowtext; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:Cambria; mso-ascii-font-family:Cambria; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Cambria; mso-hansi-theme-font:minor-latin; mso-font-kerning:1.0pt;} table.MsoTableLightShadingAccent3 {mso-style-name:"浅色底纹 - 强调文字颜色 3"; mso-tstyle-rowband-size:1; mso-tstyle-colband-size:1; mso-style-priority:60; mso-style-unhide:no; border-top:solid #9BBB59 1.0pt; mso-border-top-themecolor:accent3; border-left:none; border-bottom:solid #9BBB59 1.0pt; mso-border-bottom-themecolor:accent3; border-right:none; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:Cambria; mso-ascii-font-family:Cambria; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Cambria; mso-hansi-theme-font:minor-latin; color:#76923C; mso-themecolor:accent3; mso-themeshade:191; mso-font-kerning:1.0pt;} table.MsoTableLightShadingAccent3FirstRow {mso-style-name:"浅色底纹 - 强调文字颜色 3"; mso-table-condition:first-row; mso-style-priority:60; mso-style-unhide:no; mso-tstyle-border-top:1.0pt solid #9BBB59; mso-tstyle-border-top-themecolor:accent3; mso-tstyle-border-left:cell-none; mso-tstyle-border-bottom:1.0pt solid #9BBB59; mso-tstyle-border-bottom-themecolor:accent3; mso-tstyle-border-right:cell-none; mso-tstyle-border-insideh:cell-none; mso-tstyle-border-insidev:cell-none; mso-para-margin-top:0cm; mso-para-margin-bottom:0cm; mso-para-margin-bottom:.0001pt; line-height:normal; mso-ansi-font-weight:bold; mso-bidi-font-weight:bold;} table.MsoTableLightShadingAccent3LastRow {mso-style-name:"浅色底纹 - 强调文字颜色 3"; mso-table-condition:last-row; mso-style-priority:60; mso-style-unhide:no; mso-tstyle-border-top:1.0pt solid #9BBB59; mso-tstyle-border-top-themecolor:accent3; mso-tstyle-border-left:cell-none; mso-tstyle-border-bottom:1.0pt solid #9BBB59; mso-tstyle-border-bottom-themecolor:accent3; mso-tstyle-border-right:cell-none; mso-tstyle-border-insideh:cell-none; mso-tstyle-border-insidev:cell-none; mso-para-margin-top:0cm; mso-para-margin-bottom:0cm; mso-para-margin-bottom:.0001pt; line-height:normal; mso-ansi-font-weight:bold; mso-bidi-font-weight:bold;} table.MsoTableLightShadingAccent3FirstCol {mso-style-name:"浅色底纹 - 强调文字颜色 3"; mso-table-condition:first-column; mso-style-priority:60; mso-style-unhide:no; mso-ansi-font-weight:bold; mso-bidi-font-weight:bold;} table.MsoTableLightShadingAccent3LastCol {mso-style-name:"浅色底纹 - 强调文字颜色 3"; mso-table-condition:last-column; mso-style-priority:60; mso-style-unhide:no; mso-ansi-font-weight:bold; mso-bidi-font-weight:bold;} table.MsoTableLightShadingAccent3OddColumn {mso-style-name:"浅色底纹 - 强调文字颜色 3"; mso-table-condition:odd-column; mso-style-priority:60; mso-style-unhide:no; mso-tstyle-shading:#E6EED5; mso-tstyle-shading-themecolor:accent3; mso-tstyle-shading-themetint:63; mso-tstyle-border-left:cell-none; mso-tstyle-border-right:cell-none; mso-tstyle-border-insideh:cell-none; mso-tstyle-border-insidev:cell-none;} table.MsoTableLightShadingAccent3OddRow {mso-style-name:"浅色底纹 - 强调文字颜色 3"; mso-table-condition:odd-row; mso-style-priority:60; mso-style-unhide:no; mso-tstyle-shading:#E6EED5; mso-tstyle-shading-themecolor:accent3; mso-tstyle-shading-themetint:63; mso-tstyle-border-left:cell-none; mso-tstyle-border-right:cell-none; mso-tstyle-border-insideh:cell-none; mso-tstyle-border-insidev:cell-none;} table.MsoTableLightListAccent5 {mso-style-name:"浅色列表 - 强调文字颜色 5"; mso-tstyle-rowband-size:1; mso-tstyle-colband-size:1; mso-style-priority:61; mso-style-unhide:no; border:solid #4BACC6 1.0pt; mso-border-themecolor:accent5; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:Cambria; mso-ascii-font-family:Cambria; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Cambria; mso-hansi-theme-font:minor-latin; mso-font-kerning:1.0pt;} table.MsoTableLightListAccent5FirstRow {mso-style-name:"浅色列表 - 强调文字颜色 5"; mso-table-condition:first-row; mso-style-priority:61; mso-style-unhide:no; mso-tstyle-shading:#4BACC6; mso-tstyle-shading-themecolor:accent5; mso-para-margin-top:0cm; mso-para-margin-bottom:0cm; mso-para-margin-bottom:.0001pt; line-height:normal; color:white; mso-themecolor:background1; mso-ansi-font-weight:bold; mso-bidi-font-weight:bold;} table.MsoTableLightListAccent5LastRow {mso-style-name:"浅色列表 - 强调文字颜色 5"; mso-table-condition:last-row; mso-style-priority:61; mso-style-unhide:no; mso-tstyle-border-top:2.25pt double #4BACC6; mso-tstyle-border-top-themecolor:accent5; mso-tstyle-border-left:1.0pt solid #4BACC6; mso-tstyle-border-left-themecolor:accent5; mso-tstyle-border-bottom:1.0pt solid #4BACC6; mso-tstyle-border-bottom-themecolor:accent5; mso-tstyle-border-right:1.0pt solid #4BACC6; mso-tstyle-border-right-themecolor:accent5; mso-para-margin-top:0cm; mso-para-margin-bottom:0cm; mso-para-margin-bottom:.0001pt; line-height:normal; mso-ansi-font-weight:bold; mso-bidi-font-weight:bold;} table.MsoTableLightListAccent5FirstCol {mso-style-name:"浅色列表 - 强调文字颜色 5"; mso-table-condition:first-column; mso-style-priority:61; mso-style-unhide:no; mso-ansi-font-weight:bold; mso-bidi-font-weight:bold;} table.MsoTableLightListAccent5LastCol {mso-style-name:"浅色列表 - 强调文字颜色 5"; mso-table-condition:last-column; mso-style-priority:61; mso-style-unhide:no; mso-ansi-font-weight:bold; mso-bidi-font-weight:bold;} table.MsoTableLightListAccent5OddColumn {mso-style-name:"浅色列表 - 强调文字颜色 5"; mso-table-condition:odd-column; mso-style-priority:61; mso-style-unhide:no; mso-tstyle-border-top:1.0pt solid #4BACC6; mso-tstyle-border-top-themecolor:accent5; mso-tstyle-border-left:1.0pt solid #4BACC6; mso-tstyle-border-left-themecolor:accent5; mso-tstyle-border-bottom:1.0pt solid #4BACC6; mso-tstyle-border-bottom-themecolor:accent5; mso-tstyle-border-right:1.0pt solid #4BACC6; mso-tstyle-border-right-themecolor:accent5;} table.MsoTableLightListAccent5OddRow {mso-style-name:"浅色列表 - 强调文字颜色 5"; mso-table-condition:odd-row; mso-style-priority:61; mso-style-unhide:no; mso-tstyle-border-top:1.0pt solid #4BACC6; mso-tstyle-border-top-themecolor:accent5; mso-tstyle-border-left:1.0pt solid #4BACC6; mso-tstyle-border-left-themecolor:accent5; mso-tstyle-border-bottom:1.0pt solid #4BACC6; mso-tstyle-border-bottom-themecolor:accent5; mso-tstyle-border-right:1.0pt solid #4BACC6; mso-tstyle-border-right-themecolor:accent5;}</style>

Android研发规范

2014年博客之星投票地址:http://vote.blog.csdn.net/blogstar2014/details?username=wwj_748#content

1Android编码规范

包命名规范

包(packages):采用反域名命名规则,全部使用小写字母。一级包名为com,二级包名为xxx(可以是公司域名或者个人命名),三级包名根据应用进行命名,四级包名为模块名或层级名。

包名

说明

com.xxx.应用名称缩写.activities

页面用到的Activity类(activities层级用户界面)

com.xxx.应用名称缩写.fragment

页面用到的Fragment

com.xxx.应用名称缩写.base

页面中每个Activity类共享的可以写成一个BaseActivity类(基础共享的类)

com.xxx.应用名称缩写.adapter

页面用到的Adapter类(适配器的类)

com.xxx.应用名称缩写.utils

此包中包含:公共工具方法类(包含日期、网络、存储、日志等工具类)

com.xxx.应用名称缩写.bean

model/domain均可,个人喜好)

实体类

com.xxx.应用名称缩写.db

数据库操作

com.xxx.应用名称缩写.view(或者.ui

自定义的View类等

com.xxx.应用名称缩写.service

Service服务

com.xxx.应用名称缩写.broadcast

Broadcast服务

 

 

类命名规范

类(classes):名词,采用大驼峰命名法,尽量避免缩写,除非该缩写是众所周知的,比如HTMLURL,如果类名称包含单词缩写,则单词缩写的每个字母均应大写。

 

描述

例如

Application

Application为后缀标识

XXXApplication

Activity

Activity为后缀标识

闪屏页面类

SplashActivity

解析类

Handler为后缀标识

 

公共方法类

UtilsManager为后缀标识

线程池管理类:ThreadPoolManager

日志工具类:LogUtils

数据库类

DBHelper后缀标识

MySQLiteDBHelper

Service

Service为后缀标识

播放服务:PlayService

BroadcastReceiver

Broadcast为后缀标识

时间通知:

TimeBroadcast

ContentProvider

Provider为后缀标识

单词内容提供者:DictProvider

直接写的共享基础类

Base为前缀

BaseActivity,

BaseFragment

 

变量命名规范

变量(variables)采用小驼峰命名法。类中控件名称必须与xml布局id保持一致。

公开的常量:定义为静态final,名称全部大写。eg: public staticfinal String ACTION_MAIN=”android.intent.action.MAIN”;

静态变量:名称以s开头 egprivate static long sInstanceCount = 0;

非静态的私有变量、protected的变量:以m开头,egprivate Intent mItent;

 

 

接口命名规范

接口(interface):命名规则与类一样采用大驼峰命名法,多以ableible结尾,eginterface Runable; interface Accessible;

 

方法命名规范

方法(methods):动词或动名词,采用小驼峰命名法,egonCreate(),run();

方法

说明

initXX()

初始化相关方法,使用init为前缀标识,如初始化布局initView()

isXX()

checkXX()方法返回值为boolean型的请使用ischeck为前缀标识

getXX()

返回某个值的方法,使用get为前缀标识

processXX()

对数据进行处理的方法,尽量使用process为前缀标识

displayXX()

弹出提示框和提示信息,使用display为前缀标识

saveXX()

与保存数据相关的,使用save为前缀标识

resetXX()

对数据重组的,使用reset前缀标识

clearXX()

清除数据相关的

removeXX()

清除数据相关的

drawXXX()

绘制数据或效果相关的,使用draw前缀标识

 

布局文件命名规范

 

 全部小写,采用下划线命名法

1)contentview命名, Activity默认布局,以去掉后缀的Activity类进行命名。不加后缀:

功能模块.xml

egmain.xmlmore.xmlsettings.xml

       或者:activity_功能模块.xml

egactivity_main.xmlactivity_more.xml

2)Dialog命名:dialog_描述.xml

egdlg_hint.xml

3)PopupWindow命名:ppw_描述.xml

       egppw_info.xml

4). 列表项命名listitem_描述.xml

eglistitem_city.xml

5).包含项:include_模块.xml

eginclude_head.xmlinclude_bottom.xml

6)adapter的子布局:功能模块_item.xml

egmain_item.xml

 

资源id命名规范

 命名模式为:view缩写_模块名称_view的逻辑名称

view的缩写详情如下:

控件

缩写

LayoutView

lv

RelativeView

rv

TextView

tv

Button

btn

ImageButton

imgBtn

ImageView         

iv

CheckBox           

cb

RadioButton        

rb

analogClock        

anaClk

DigtalClock        

dgtClk

DatePicker         

dtPk

EditText           

edtTxt

TimePicker         

tmPk

toggleButton       

tglBtn

ProgressBar 

proBar

SeekBar                            

skBar

AutoCompleteTextView

autoTxt

ZoomControls       

zmCtl

VideoView          

vdoVi

WdbView            

webVi

RantingBar         

ratBar

Tab                

tab

Spinner            

spn

Chronometer        

cmt

ScollView          

sclVi

TextSwitch         

txtSwt

ImageSwitch        

imgSwt

listView           

lVi 或则lv

ExpandableList     

epdLt

MapView            

mapVi

 

动画文件命名

 动画文件(anim文件夹下):全部小写,采用下划线命名法,加前缀区分。

 

//前面为动画的类型,后面为方向

动画命名例子

规范写法

备注

fade_in

淡入

 

fade_out

淡出

 

push_down_in

从下方推入

 

push_down_out

从下方推出

 

push_left

推像左方

 

slide_in_from_top

从头部滑动进入

 

zoom_enter

变形进入

 

slide_in

滑动进入

 

shrink_to_middle

中间缩小

 

 

 

图片资源文件命名

命名

说明

bg_xxx

这种图片一般那些比较大的图片,比如作为某个Activity的背景等

btn_xxx

按钮,一般用于按钮,而且这种按钮没有其他状态

ic_xxx

图标,一般用于单个图标,比如启动图片ic_launcher

bg_描述_状态1[_状态2]

用于控件上的不同状态

btn_描述_状态1[_状态2]

用于按钮上的不同状态

chx_描述_状态1[_状态2]

选择框,一般有2态和4

 

 

 

 

 

一些常见的单词缩写

名称

缩写

icon  

ic (主要用在app的图标)

color  

cl(主要用于颜色值)

divider

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

selector

sl(主要用于某一view多种状态,不仅包括Listview中的selector,还包括按钮的selector

average

avg

background  

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

buffer

buf

control

ctrl

delete

del

document 

doc

error

err

escape

esc

increment

inc

infomation

info

initial 

init

image

img

Internationalization

I18N

length

len

library

lib

message

msg

password-

pwd

position

pos

server

srv

string

str

temp

tmp

window

wnd(win)

  

 

 

Android研发规范