Fourth. Android naming conventions and coding specifications

Source: Internet
Author: User

The book is more common, and individual people have different views;

Because Android is mostly developed using Java, Java-related specifications apply to Android:

Google Style:

English Address: http://google-styleguide.googlecode.com/svn/trunk/javaguide.html

Chinese translation: http://www.blogjava.net/zh-weir/archive/2014/02/08/409608.html

Then say my naming conventions and coding specifications in Android development:

First share a specification that I often refer to:

http://blog.csdn.net/vipzjyno1/article/details/23542617

http://blog.csdn.net/wwj_748/article/details/42347283

Basically similar content

Activity naming specification: page name +activity;

Adapter naming specification: page name +adapter;

Entity naming specification: The book is a module or page name +entity, but my personal habit is the interface name suffix +result (this if there is an opinion, can be discussed in the comment area).

Resource File name:

Page layout file: Unlike in the book, I was named after the activity or frament file naming statements, such as the Loginactivity,laout file will be named Activity_login.xml;

The ListView item file starts with item, ends with the name of the list, and remains consistent with the book.

drawable file naming specification: Press the background switch to end with selector;

In the book is a more excellent view:

Only one page uses the file, with the page name as the prefix;

If a file is used by multiple files of a module, the module is prefixed;

If more than one module is used, the common is the most prefixed.

Common control Abbreviations:

Shared with the following Web pages

http://blog.csdn.net/vipzjyno1/article/details/23542617

With respect to naming the ID in layout and initializing the view control variable, I am consistent with the book and are consistent with the naming in the layout, which facilitates copying and pasting.

On the color naming, I think the name of the color is not very good, my way is color_dc181c = "#dc181c" this form.

The same is true for the designation of dimensions, my name is DIMEN_45DP = "45DP".

The unity of code style in Android, in addition to the specification, can be through template mode, in the base class to standardize the style of the unified, through the abstract method to control, such as Initview () and Initdate (), component Click event This abstract method encapsulated in the base class, Each team member writes code, must inherit from your base code, then writes in the unified code block.

The layout file does not have constant data encapsulated in the String.xml file, it is not recommended to deal with the file inside.

Layout previews can be controlled by means of tool:

<button    android:id= "@+id/button2"    android:layout_width= "Wrap_content"     Android:layout_height= "Wrap_content"    android:text= "Second"    tools:visibility= " Visible "/>

Similar also has Tools:text = "Android" this way.

Adapter binding Data is ArrayList, this is agreed.

Network operations or picture caches are recommended for processing using a mature library, rather than creating a custom wheel handle.

Come in using the context of the application instead of using the activity context because it is prone to memory leaks.

Use constants instead of enumerations.

Finally recommended two specifications and methods of bug tools, Androidstudio format Unified code style checkstyle,findbugs.

Fourth. Android naming conventions and coding specifications

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.