Android Programming Development Specification

Source: Internet
Author: User

Android Programming Development Specification

Original text address http://www.jianshu.com/p/9b8aeca9b281

I. Convention

   activity.oncreate (), fragment.onactivitycreated (), as a program entry, without writing too much code, try to keep only calling the Initxxx () method, Simple and straightforward presentation call process. such as: InitData (), Initview ().  a single method body do not place too long code anywhere do not misspell the word  eliminate the entire class code formatting  calling method keep the proximity principle, called method, placed under the calling method  Uniform adjustment of the IDE's tab indentation to 4 spaces  empty line of use, refusing to procrastinate without splitting, the associated code snippet put a piece and split with the following code with good todo tag to record ideas, record function points, The development process can use TODO to record a temporary idea or to leave the idea of not disturbing left to perfect instructions to delete useless Todo, the development tool automatically generated TODO, or already perfect todo, be sure to delete.     handle mysterious numbers such as magic number  do not appear in the code, especially if you identify different types of numbers. All meaning figures are extracted into the constant public class, and are not scattered among the classes. 

Two. naming
1. Naming the ID in the layout file

Rule: Use hump naming, prefix + logical name, class variable name and layout file ID name to be consistent, no underscore split

Control prefix rules:

TextView/EditText: tv/etButton/RadioButton/ImageButton: btnImageView: imgRelativeLayout/LinearLayout/FrameLayout: layout,ListView: listViewWebView: webViewCheckBox: chBox如:TextView @+id/tvTitle如:EditView @+id/etName如:Button @+id/btnSearch

2. layout file naming

Rule: Use the prefix _ logical name, the words are all lowercase, the words are divided by an underscore.

Prefix rules:

Activity对应的布局使用activity_  有时候类名过长 可简写为atyFragment对应的布局使用fragment_   简写 fgt如:PublishActivity: activity_publish.xml   PublishAty 

3. resource file naming

Rule: Use prefix _ Use name, the words all lowercase, the words are divided by an underscore.

drawable:    btn_back_selector.xml 控件前缀命名    common_circle_gray.xml 通用资源多处使用common_    chat_image_selector.xml 功能相关业务使用加用途前缀drawable_hdpi:    btn_back_normal.9.png 控件前缀名称    btn_back_press.9.png 控件前缀名称    icon_login_lock.png icon_+用途values/color:    pull_refresh_attrs.xml 引入的第三方资源,携带资源简拼的前缀

4. Class and interface naming

Rule: Using hump rules, the first letter must be capitalized, using nouns or noun phrases. The requirements are straightforward, descriptive, and do not allow for meaningless or erroneous words.

如:class BookMarkAdd 正确如:class AddBookReadPlan 错误! 应为 class BookReadPlanAdd 

5. Method naming

Rule: Using hump rules, the first letter must be lowercase, using verbs. The requirements are straightforward, descriptive, and do not allow for meaningless or erroneous words.

如:public void run();如:public String getBookName(); 

6. Variable naming

Rule: Using hump rules, the first letter must be lowercase, using nouns or noun phrases. The requirements are straightforward, descriptive, and do not allow for meaningless or erroneous words.

成员变量命名,不要在私有变量前添加m字样常量命名,全部大写,单词间用下划线隔开

7. Other

空行:空行将逻辑相关代码段隔开,简洁清楚,提高可读性    成员变量之间,根据业务形成分组加空行    方法之间加空行控制语句    减少条件嵌套,不要超过3层    if判断使用“卫语句”,减少层级    if(obj != null) { doSomething();}    修改为:    if(obj == null) { return;}doSomething();    if语句必须用{}包括起来,即便是只有一句方法    拆分臃肿方法,每个方法只作一件事    做同一个逻辑的方法,尽量靠近放到一块,方便查看    不要使用 try catch 处理业务逻辑    使用JSON工具类,不要手动解析和拼装数据Activity继承BaseFragmentActivity或SwipeBackActivity,可以使用ButterKnife注解代替findViewById。

Three. IDE

Android Studio (越早使用越好)Android SDK 4.4W (API 20 统一开发版本)JDK 1.8(统一开发版本)

Four. Libraries

Base

fastjson-android-1.2.4.jarokhttp-2.2.0.jarokio-1.2.0.jarpicasso-2.5.0.jarbutterknife:7.0.1ormlite-android:4.48volley

Ui

PullToRefreshQuickAdapterPagerSlidingTabStripSystemBarTint 状态栏以及导航栏设置背景颜色SwipeBackLayout 左滑返回PullToZoomView 可以下拉缩放HeaderViewAutoLoopViewPager 轮播图PhotoViewViewPageIndicator

Android Programming Development Specification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.