Android encoding and naming specification

Source: Internet
Author: User

Android encoding Specification class name: Big Hump (Pascal) nomenclature: Also weigh hump nomenclature, the first letter of all words capitalized method function: Small hump (Camel) nomenclature: Also known as the Small Hump name method, except the first word, all the remaining words of the first letter capitalized. Constants: Underline naming: Words are spaced between words with underscores. All CAPS! Some definitions of variable specifications in code: member variables: m_***             Local variables: l_***           parameters: a_*** Volume: Uppercase _***                   enumeration value: em_*** The ID in the Layout XML file named view abbreviation _ Module name _view logical name Example: Tv_setting_password defining the variable name of the control in code m_view abbreviation _ module name _view Logical name Example: Tv_setting_password (consistent with the ID in the XML layout file) control abbreviation Layoutview Lav relativeview RV TextView TV Button btn ImageButton         IMGBTN ImageView   &nbs P     IV CheckBox           CHK RadioButton         RDOBTN Analogcloc K         ANACLK digtalclock         DGTCLK DatePicker         DTPK EditText           Edttxt timepicker         TMPK ToggleButton   & nbsp   TGLBTN PRogressbar Probar SeekBar                           &NBSP ; Skbar Autocompletetextview autotxt zoomcontrols       ZMCTL videoview           VD OVi Wdbview             WEBVI Rantingbar         Ratbar Tab   &NBSP ;             tab Spinner             SPN chronometer   &NB Sp     CMT Scollview           Sclvi textswitch         TXTSWT IMAGESW Itch         IMGSWT ListView           LV expandablelist     EPDLT Mapview             MAPVI Package name specification: Package (Packages): Use anti-domain naming rules, all lowercase letters. The first level package name is COM, level two package name is XX (can be company or personal casual), three level package name according to the application name, four level package name is the module name or the level name Package name This package contains COM.XX. Application name abbreviation. Activity class used by Activities page ( Activities level name user interface layer) com.xx. Apply the name abbreviation. Each activity class in the base page is sharedTo write an I-baseactivity class (the underlying shared class) com.xx. Apply the name abbreviation. adapter   Page Adapter class (adapter Class) com.xx. Apply name abbreviation. Tools This package contains: Public Tools method Class (Tools module name) com.xx. The application name abbreviation. Bean This package contains: element class com.xx. The application name abbreviation. DB database Operation class com.xx. Application name abbreviation. View Custom View class com.xx. Application name abbreviation. Service     Service com.xx. Application name abbreviation. Broadcast   Broadcast service class naming: Description For example activity class activity as suffix Identify welcome Page class Welcomeactivity Adapter class adapte to suffix identify news details Adapter  newdetailadapter resolve class HLR suffix identify first page parsing class Homeposterhlr public method class   Tools or manager identifies thread pool management classes for suffixes: Threadpoolmanager?         Logging Tool class: Logtools database class identifies a news database with a dbhelper suffix: Newdbhelper service class identifies time services Timeservice Br with service suffix Oadcastreceive class   The broadcast suffix identifies the time notification Timebroadcast ContentProvider   The shared base class that identifies the direct write with the provider suffix begins with base Baseactivity,basefragment Methods (methods): verbs or verb nouns, using small hump nomenclature such as: OnCreate (), run () to illustrate INITXX () initialization of related methods, using init as the prefix identifier, If the Initialize Layout Initview () isxx () checkxx () method returns a Boolean value, use is or check to identify Getxx () method that returns a value, using get as a prefix to identify the method by which processxx () handles the data, Try using process as a prefix to identify the displayxx () pop-up cue box and the prompt message, using DISPLAy is a prefix identifying Savexx () associated with saving data, using the save prefix to identify RESETXX () for data reorganization, using the reset prefix to identify clearxx () to purge data related removexxx () to purge data related drawxxx () To draw data or effects related, use the draw prefix to identify drawable resource naming: Resource files (under the Picture drawable folder): All lowercase, with underscore naming, prefix naming pattern: Activity Name _ Logical name/public: Common_ Logical name Name feature btn_xx button picture use btn_ overall effect (selector) Btn_xx_normal button picture use btn_ Normal effect btn_xx_press button picture use Btn_ Click Time Effect bg_head background image use Bg_ function _ Description Def_search_cell default Picture Use Def_ function _ description icon_more_help icon Picture Use Icon_ Function _ description seg_list_line have delimited feature picture use Seg_ function _ description SEL_OK Select Icon Use sel _ function _ description name suffix: Suffix description unit When using XML Tilemode to match the picture, the element image uses the state of the suffix nor picture, representing the state of the normal state HL picture, representing the state of the highlighted state press picture, representing the status of the select picture Status, which represents the state of the view that it occupies is selected unselect picture, which represents the view that it occupies is not a quantifier suffix (when in a set of data): With a uniform quantifier by placing a quantifier at the end, 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   Last of a set of variables   The final next in a set of variables Prev   the previous Cur     Group in a set of variables The current variable in the variable resource layout file (XML file (layout file)): All lowercase, using the underscore name 1). Activity naming,   activity_ function module. XML        For example: Activity_main.xml, Activity_more.xml 2). Dialog name: Dialog_ description. xml       For example: Dlg_hint.xml 2). Popupwindow Name: ppw_ description. xml       For example: PPW _info.xml 3). List item name listitem_ description. xml       For example: Listitem_city.xml 4). Include: Include_ module. XML       For example: Include_head.xml, Include_bottom.xml 5). Adapter sub-layout: function module _item.xml For example: Main_item.xml, 6). Custom View:view_ module name. xml animation file naming: Animation files (under the Anim folder): All lowercase, using the underscore naming method, plus the prefix distinction. Preceded by the type of animation, followed by a direction animation named Example specification notation fade_in fade-in fade_out fade-out push_down_in push from below push_down_out from below Push_left push like left Slide_in_from _top from the head sliding into the zoom_enter deformation into the slide_in sliding into the shrink_to_middle middle of narrowing strings.xml,colors.xml and so on the ID named: Naming mode: Activity name _ Function Module Name _ Logical name/activity Name _ logical name/common_ logical name Strings.xml, using activity name annotation, separating the contents of the file the following are the contents of the activity the following is the specification recommendation: 1. Chinese is not present in the Java code, the maximum number of comments can appear in Chinese 2. Local variable naming, static member variable naming can contain only letters, the first letter of the word is uppercase, and the other letters are lowercase 3. A constant name can contain only letters and _, all uppercase letters, and words separated by _ 4. Picture as many reusable pictures as possible 5. The server can be implemented, do not put on the client 6. It is prudent to refer to third-party libraries to avoid the application of large-capacity third-party libraries, resulting in a very large client package of 7. Handles applying global exceptions and errors, sending errors to the service as a message8. The. 9 Processing of the picture 9. Using static variables to realize the sharing between interfaces be cautious 10.Log (System name Module name Interface name, detailed description) 11. Unit Test (logic test, Interface Test) 12. Do not reuse the handler of the parent class. A handler corresponding to a class should not be used by its subclasses, otherwise it will cause message.what conflict 13.activity to be used in a view.onclicklistener to handle all logical 14.strings.xml in%1$ s implements the wildcard of strings 15. If multiple activity contains common UI processing, you can refine a commonactivity, call the generic part to handle it, and other activity just inherit it 16. Use button+ Activitgroup When you implement the tab effect, use button.setselected (true) to make sure that the button is selected and that the current activity of activitygroup corresponds to 17. If you are developing a generic component, To avoid conflicts, add a prefix of 18 to the file name in the Drawable/layout/menu/values directory. Data must be validated, such as the character type to digital type, if the conversion fails to have a default value, the service side response data is valid judgment 19. The view variable naming pattern in activity is: Logical name +view abbreviated recommendation: If the layout file is complex, it is recommended that layout be divided into modules, each module defining a moduleviewholder whose member variables contain the owning view 20. Styles.xml: The continuous style of layout is extracted from the common style generic components, put into the styles.xml;

Android encoding and naming conventions

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.