Android Development Specification-naming

Source: Internet
Author: User
Tags custom graphics

Before we explain the naming specification, we introduce the main identifier naming method and English abbreviation rules at first.

Identifier naming method

There are four types of identifier naming methods:

1 Hump (Camel) Nomenclature: Also known as the small hump nomenclature, except for the first word, the first letter of all the remaining words capitalized.

2 Pascal (PASCAL) nomenclature: Also weigh hump nomenclature, the first letter of all words capitalized

3 underline naming: The words and the words are underlined between the intervals.

4 Hungarian nomenclature: Widely used in the Microsoft programming environment, the type of the variable is indicated by attaching a lowercase sequence before a variable that is named Pascal. The amount is named:<scope_> + <prefix_> + <qualifier> range prefix, type prefix, qualifier.

Personally feel the identifier naming principle: as far as possible with the fewest characters and can fully express the meaning of the identifier.

English abbreviation principle:
1 shorter words can be abbreviated by removing "vowels"
2 longer words are desirable for the first few letters of a word to form abbreviations
3 In addition, there are some conventions idiomatic the English word abbreviation.

The following are common abbreviations for English words:
Average----> Avg
Background---&GT;BG
Buffer-----&GT;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)
The word abbreviation principle is used in the program: do not use abbreviations unless the abbreviation is customary.

Naming conventions:

1 Pack (Packages): Use the anti-domain naming rules, all using lowercase letters. The first-level package is named COM, two
Class Package name is Anjoyo, level three package name is named according to the application, level four package name is module name or hierarchy name


For example:
Com.anjoyo. Application. Activities This package contains: Activity class used by the page (Activities level name user interface layer)
Com.anjoyo. Applications. Tools This package contains: Common Tools method classes (Tools module name)
Com.anjoyo. Application. DB included in this package: Database operations Classes
Com.anjoyo. Application. Custom This package contains: Customized view class, etc.
Com.anjoyo. Application. Service included in this package: service services
Com.anjoyo. Application. Broadcast included in this package: Broadcast Service

Class 2 (classes): Nouns, using the big hump nomenclature, try to avoid abbreviations, unless the abbreviation is well known,
For example Html,url, if the class name contains a word abbreviation, each letter of the acronym should be capitalized.

Activity class Aty is the suffix identifier, such as Welcome Page class Welcomeaty.
Adapter class ADP is a suffix identifier, such as commodity detail adapter PRODUCTDETAILADP
The parsing class HLR is the suffix identifier, such as the first page parsing class HOMEPOSTERHLR
Public methods class tools or manager are identified as suffixes. For example: Thread pool Management class: Threadpoolmanager
Log Tool class: Logtools
The database class is identified with the DBHelper suffix. such as City database: Citydbhelper
Service class is identified with service suffix
Broadcastreceive with broadcast as suffix
ContentProvider with provider as suffix

3 Interface (interface): Naming rules and classes using the big hump nomenclature, more able or ible end, such as interface Runna ble;
Interface Accessible.

4 Methods (methods): verbs or verb nouns, using small hump nomenclature such as: OnCreate (), run ()

Initxxx () Initializes the associated method, using the init prefix to identify
Isxxx () checkxxx () method returns a Boolean value using is or check for prefix identification
GetXXX () method that returns a value, using get as a prefix to identify
Processxxx () Method of processing data, using process as a prefix to identify
Displayxxx () pop-up prompts and hints, using display as a prefix to identify
Savexxx () associated with saving data, using SAV to identify the e prefix
Resetxxx () for data reorganization, use the reset prefix to identify
Clearxxx () removexxx () Clear data related, use clear or remove for prefix identification
Drawxxx () drawing data or effects related, using the draw prefix to identify

The 5 variable (variables) uses the small hump name method. The name of the control in the class must be consistent with the XML layout ID.

1 View variable naming: control type description + meaning description
Control abbreviation
TextView txt
Button BTN
ImageButton imgbtn
ImageView Imgview
CheckBox chk
RadioButton rdobtn
AnalogClock ANACLK
Digtalclock DGTCLK
DatePicker DTPK
Timepicker TMPK
ToggleButton tglbtn
EditText Edttxt
ProgressBar Probar Probar
SeekBar Skbar
Autocompletetextview Autotxt
Zoomcontrols Zmctl
Include IND
Videoview Vdovi
Wdbview Webvi
Rantingbar Ratbar
TAB tab
Spinner SPN
Chronometer CMT
Scollview Sclvi
Textswitch TXTSWT
Imageswitch IMGSWT
ListView LVi
Expandablelist EPDLT
Mapview MAPVI

By placing a quantifier at the end of a uniform quantifier, you can create more uniform variables that are easier to understand and easier to search. For example, use Strcustomerfirst and strcustomerlast instead of using Strfirstcustomer and Strlastcustomer.
quantifier list: quantifier suffix description
First a set of variables
Last of a set of variables
Next variable in a set of variables
Prev the previous in a set of variables
Cur the current variable in a set of variables

6 Constants (constants) are all capitalized and are underlined. For example: Min_width

7 XML file (layout file): All lowercase, using the underscore name method
1. The activity default layout, named after the activity class with the suffix removed. Do not add suffix
2. Activity sub-layout, the parent layout name begins, and the item and sub-layout feature descriptions are appended.
Example: Activity default layout: Homeposter.xml sub-layout is Homeposter_item_poster.xml

8 resource file (image): All lowercase, using the underscore name, plus the prefix to distinguish

Btn_login_normal

button picture using Btn_ function _ description

Bg_head

Background image using Bg_ function _ description

Def_search_cell

Default picture using Def_ Function _ description

Icon_more_help

Icon Picture using Icon_ Function _ description

Seg_list_line

Images with delimited features use the Seg_ function _ description

Sel_ok

Select icon Using Sel_ function _ description


9 Animation files (Anim package): All lowercase, using the underscore naming method, plus the prefix distinction.

Animation naming Example

Standard notation

Note

Click_head_left

Click Background Toggle Animation using the click prefix to identify

Bg_shape_rectangle

Background custom graphics using the BG prefix identifier

Show_shopcar_add

Small animation effects are identified with the show prefix


10 Resource ID: The case specification is consistent with the method name, using the small hump naming method. The naming convention is "abbreviated name of resource control" + "variable name". Attention: the page control name should be consistent with the control ID name
Related Article

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.