1.资源文件命名规则
2.类名文件命名规则
3.尽量少用枚举
4.public方法、重要逻辑、主要类结构体必须注释,其他部分可自定注释
5.提交代码必须描述清楚修改内容,如果一次提交内容过多,拆分功能进行多次提交,尽量保持每次提交功能修改单一原则
6.类文件尽量不超过300行,方法尽量不超过一个屏幕
7.切忌在功能未完成时做过多类文件的重构
8.坚持以上7点,成为优秀码农 ############################################################
# Android Coding Standards #
# #
# https://github.com/47deg/coding-guidelines/tree/master/java/android#android-coding-standards #
############################################################ 1. Naming Conventions Developers should pay special attention to these naming conventions as they differ from those in the standard Java Coding Conventions. 1.1. Common Resource Files The folder values will have different files that will store information for our project. Some of the most common files and their name are colors.xml: Colors used in the application
config.xml: Stores information to configure our project (ex. keys for services, urls, etc)
dimen.xml: Dimensions used in application (ex. action bar height , paddings, etc)
strings.xml: Localizable strings
plurals.xml: Plurals. Contains references to strings.xml
arrays.xml: Arrays. Contains references to strings.xml
1.2. Java Packages & Class Names An android App should generally follow the following package structure com.company.product.android
activities: All Activities with the word Activity pre-fixed by the Activity name: *[Name]*Activity e.g. MainActivity
adapters: All Adapters with the word Adapter pre-fixed by the Adapter name: *[Name]*Adapter e.g. UserListAdapter
services: All Services including API clients and other persistence related services e.g. UserService
components: All reusable components utilized in Activity and Fragments e.g. UserProfileComponent
dialogs: All Fragment Dialogs with the word Dialog pre-fixed by the dialog name: *[Name]*Dialog e.g. DeleteAccountConfirmationDialog
fragments: All Fragments with the word Fragment pre-fixed by the Fragment name: *[Name]*Fragment e.g. UserMapLocationFragment
utils: All cross package utilities with the word Utils pre-fixed by the Utility name: *[Name]*Utils e.g. StringUtils
1.3. Resource Names The following structure should be followed when naming resoures. group _ type _ name _ [state] _ [suffix] Group: Application area or screen. If the resource is used in different parts of applications 'common' should be used instead. e.g. actionbar, menu, media, popup, footer, audio, etc.
Type: Resource Type. e.g. background, icon, button, textfield, list, menuitem, radiobutton, checkbox, tab, dialog, title, etc.
Name: Descriptive name as to what the resource is about. e.g. play, stop.
State: (Optional): The optional state of a parent resource. e.g. A button could be in 'normal', 'pressed', 'disabled' and 'selected'. A checkbox could be 'on' or 'off'. These resources should NEVER be used directly in layout but rather as state selectors.
Suffix: (Optional): An arbitrary suffix that helps to further identify a property of the resource. e.g. bright, dark, opaque, layer.
Below are some examples of properly named resources. common_background_app
audio_icon_play_on
common_icon_preferences
actionbar_button_send (XML resource)
action_button_send_normal
action_button_send_pressed
action_button_send_disabled
1.4. String Resources String resources placed in xml resources files such as strings.xml, config.xml, etc. are named following the same convention as Java naming conventions for variables and fields. CamelCase with the first letter lowercased. Below are some examples of properly named string identifiers. serverApiUrl
phoneNumber
services
url
1.5. Style Resources String resources placed in styles.xml are named in CamelCase. The following structure should be followed when naming style resoures. [Group]TypeName[Suffix] Group (Optional): Application area or screen. e.g. actionbar, menu, media, popup, footer, audio.
Type: Resource Type. e.g. Background, Icon, Button, Textfield, List, MenuItem, RadioButton, Checkbox, Tab, Dialog.
Name: Descriptive name as to what the resource is about. e.g. play, stop.
Suffix: (Optional): An arbitrary suffix that helps to further identify a property of the resource. e.g. Bright, Dark, Opaque, Layer.
Below are some examples of properly named string identifiers. ButtonSend
ActionBarButtonBack
ListTitle
1.6. Dimen Resources Dimens resources placed in dimen.xml. The following structure should be followed when naming dimentions. property _ default _ group _ type _ name property: Type of property reference. e.g. font_size, padding, margin, height, width.
default (Optional): Write "default" if is a general dimen.
group (Optional): Application area or screen. e.g. action_bar, menu, popup, wizard.
type (Optional): Type of resource. e.g. button, title, text, edittext.
name (Optional): Only if is necessary.
Below are some examples. padding_default
font_size_action_bar_button
height_default_action_bar
We should have some dimension in all projects by default. These are: padding_default
margin_default
font_size_default_button
font_size_default_title
font_size_default_text
height_default_action_bar
font_size_default_action_bar
2. Conventions for 7" devices 7" devices require a special treatment. The problem is that these devices usually use "mdpi" as default density. These are the consideration to follow when targeting apps in these devices Copy hdpi drawables to "drawable-sw600dp-mdpi".
Create a new dimensions file for this screens. The file "dimen.xml" will be in the "values-sw600dp-mdpi" folder. Usually the dimensions will be at 150%. All fonts sizes should be in dimen.xml file as well.

资源命名准则:

==============================================
drawable:
{group _ type _ name _ [state] _ [suffix]}
==============================================
id:
{group _ ui _ type _ [local] _ name}
==============================================
layout:
{[group] _ ui _ name}
==============================================
menu:
{[group] _ ui _ name}
==============================================
anim:
{group _ name _ [local]}
==============================================
string:
{group _ [ui] _ name}
==============================================
dimen:
{group _ name _ property _ [size]}
==============================================
**********************************************
group:
[common|uikit|sdk|app] ui:
[main|kitchen|home|activity|fragment|view|actionbar|...] type:
[bg(background)|ic(icon)|bt(button(必须有状态))|txt(textfield)
|list(listview)|menu(menuitem)|radio(radiobutton)|checkbox|...] local:
[top|head|bottom|left|right|in|out|rotate|...] property:
[font|padding|margin|height|width|...] size:
[large|big|normal|small|double|treble|...] state:
[normal|pressed|disabled|on|off|...] suffix:
[light|dark|...]
==============================================
**********************************************

Android代码书写规范的更多相关文章

  1. WEB标准:标准定义、好处、名词解释、常用术语、命名习惯、浏览器兼容、代码书写规范

    1. WEB标准是什么? “WEB标准”是一系列标准的总称.一般的误区经常把WEB标准说成DIV+CSS.准确的说法应该是:采用W3C推荐的WEB标准中的XHTML1.1结合CSS2.0 样式表制作页 ...

  2. (转)Java代码书写规范

    0. 安装阿里代码规范的eclipse插件 https://www.cnblogs.com/caer/p/7753522.html 1.基本原则 强制性原则:     1.字符串的拼加操作,必须使用S ...

  3. C#中的代码书写规范以及命名规范

    C#代码书写规则: 1. 尽量使用接口,然后使用类实现接口,以提高程序的灵活性. 2.一行不要超过80个字符 3.尽量不要手动更改计算机生成的代码 4.关键的语句写注释 5.建议局部变量在最接近使用它 ...

  4. Unity项目代码书写规范

    以Google的代码规范为主,稍加改动 https://google.github.io/styleguide/csharp-style.html 书写规范 基础写法 Pascal和驼峰混用,参数用驼 ...

  5. C++代码书写规范——给新手程序员的一些建议

    代码就是程序员的面子,无论是在工作中在电脑上写程序代码还是在面试时在纸上写演示代码我们都希望写出整洁,优雅的代码.特别在工作中当我们碰到需要维护别人的代码,或者是多人参与一个项目大家一起写代码的时候, ...

  6. 【转】JavaScript常用代码书写规范

    javascript 代码规范 代码规范我们应该遵循古老的原则:“能做并不意味着应该做”. 全局命名空间污染 总是将代码包裹在一个立即的函数表达式里面,形成一个独立的模块. 不推荐 1 2 3 var ...

  7. JavaScript常用代码书写规范

    javascript 代码规范 代码规范我们应该遵循古老的原则:“能做并不意味着应该做”. 全局命名空间污染 总是将代码包裹在一个立即的函数表达式里面,形成一个独立的模块. 不推荐 , y = ; c ...

  8. Python代码书写规范

    Python 编码规范 一 代码编排1 缩进.4个空格的缩进(编辑器都可以完成此功能),不要使用Tap,更不能混合使用Tap和空格.2 每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换行点要在 ...

  9. c: c代码书写规范

    排版: 较长的语句或函数过程参数(>80字符)要分成多行书写, 长表达式要在低优先级操作符处划分新行,操作符放在新行之首, 划分出的新行要进行适当的缩进,使排版整齐,语句可读 参考: 1. 运算 ...

随机推荐

  1. [P4721] 分治 FFT

    「题意」给定\(g[0]=1\),\(g[1~n-1]\)求序列\(f[i]=\sum_{j=1}^i f[i-j]*g[j]\ , i\in[1,n-1],f[0]=1\). 「分析」分治处理区间[ ...

  2. MongoDB分片详解

    分片是MongoDB的扩展方式,通过分片能够增加更多的机器来用对不断增加的负载和数据,还不影响应用. 1.分片简介    分片是指将数据拆分,将其分散存在不同机器上的过程.有时也叫分区.将数据分散在不 ...

  3. python 时间模块time,datetime

    模块(module)是 Python 中非常重要的东西,你可以把它理解为 Python 的扩展工具.换言之,Python 默认情况下提供了一些可用的东西,但是这些默认情况下提供的还远远不能满足编程实践 ...

  4. Android studio 编译出现的问题记录

    1.app:transformClassesWithJarMergingForDebug'. Error:Execution failed for task ':app:transformClasse ...

  5. ZooKeeper系列(6):ZooKeeper的伸缩性和Observer角色

    ZooKeeper系列文章:https://www.cnblogs.com/f-ck-need-u/p/7576137.html#zk 1.ZooKeeper中的角色 在比较老的ZooKeeper版本 ...

  6. 翻译:DECLARE Variable(已提交到MariaDB官方手册)

    本文为mariadb官方手册:DECLARE Variable的译文. 原文:https://mariadb.com/kb/en/library/declare-variable/我提交到MariaD ...

  7. python下载安装BeautifulSoup库

    python下载安装BeautifulSoup库 1.下载https://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/ 2.解压到解压 ...

  8. js模块化编程之彻底弄懂CommonJS和AMD/CMD!

    先回答我:为什么模块很重要? 答:因为有了模块,我们就可以更方便地使用别人的代码,想要什么功能,就加载什么模块.但是,这样做有一个前提,那就是大家必须以同样的方式编写模块,否则你有你的写法,我有我的写 ...

  9. HTTP状态码以及其含义大全

    HTTP状态码(英语:HTTP Status Code)是用以表示网页服务器超文本传输协议响应状态的3位数字代码.我们在开发过程中比较常见的状态码有:200(请求成功).301(页面重定向).404( ...

  10. C#开源框架(转载)

    Json.NET http://json.codeplex.com/ Json.Net 是一个读写Json效率比较高的.Net框架.Json.Net 使得在.Net环境下使用Json更加简单.通过Li ...