我要寻找一个彻底的Android命名约定建议。 我发现从这里一点点 -
http://source.android.com/source/$c$c-style.html#follow-field-naming-conventions
它说,
在非公开,非静态字段名以m开始的。 在静态字段名称开头秒。 在其他领域开始与小写字母。 公共静态最终字段(常量)是ALL_CAPS_WITH_UNDERSCORES。但我在寻找一些更广泛的覆盖安卓的各个方面 -
如何在命名布局和视图, 如何命名menues 如何命名风格 如何命名在数据库表(单数,复数)和字段 等等等等我是那种太愚蠢,使一些弥补自己,最后总是做不同取决于我的心情。此外,如果有一些普遍接受的建议,我只是喜欢遵循。所有的软件开发工具包似乎走自己的路让我特别感兴趣的是Android的方式来做到这一点。
感谢。
解决方案 的XML文件1.Naming约定
activity_<活动名称>的.xml - 所有活动
dialog_<对话框名称>的.xml - 适用于所有自定义对话框
row_< LIST_NAME>的.xml - 自定义行列表视图
fragment_< FRAGMENT_NAME>的.xml - 适用于所有的碎片
2.命名约定组件/插件在XML文件中。
所有的组件对于x活动必须开始与活动名称
所有组件都应具有preFIX或简称如BTN的按钮
例如,对于登录活动组件的名称应该像下面。
activity_login_btn_login
activity_login_et_username
activity_login_et_password
主要成分的短名称
按钮 - BTN
的EditText - 等
的TextView - 电视
复选框 - CHK
单选按钮 - RB
切换按钮 - 结核病
微调 - SPN
菜单 - MNU
ListView控件 - LV
GalleryView - GV
的LinearLayout -ll
RelativeLayout的 - RL
I am looking for a thorough android naming convention suggestion. I found a little bit from here -
http://source.android.com/source/code-style.html#follow-field-naming-conventions
which says,
Non-public, non-static field names start with m. Static field names start with s. Other fields start with a lower case letter. Public static final fields (constants) are ALL_CAPS_WITH_UNDERSCORES.yet I am looking for something much more extensive covering all aspects of android-
how to name layouts and views within, how to name menues how to name styles how to name database tables (singular, plural) and fields within etc etc etcI am kind of too stupid to make something up for myself and always end up doing it differently depending on my mood. Also if there is some generally accepted suggestion I would just love to follow that. All sdks seem to go their own way so I am particular interested in the android way to do it.
Thanks.
解决方案1.Naming convention for Xml files
activity_<ACTIVITY NAME>.xml - for all activities
dialog_<DIALOG NAME>.xml - for all custom dialogs
row_<LIST_NAME>.xml - for custom row for listview
fragment_<FRAGMENT_NAME>.xml - for all fragments
2. Naming convention for component/widget in xml files.
all component for x activity must be start with activity name
all component should have prefix or short name like btn for button
For example,name for login activity component should be like following.
activity_login_btn_login
activity_login_et_username
activity_login_et_password
Short name of major components
Button - btn
EditText - et
TextView - tv
Checkbox - chk
RadioButton - rb
ToggleButton - tb
Spinner - spn
Menu - mnu
ListView - lv
GalleryView - gv
LinearLayout -ll
RelativeLayout - rl