Android 命名规范1---工程文件命名

* 翻译 * From ribot

1. Android项目指南

1.1 工程结构

参考Android构建标准结构

1.2 文件命名

1.2.1 Class files类文件

类名遵循UpperCamelCase.

对与继承Android组件的类,类名应该以组件结尾。例如: SignInActivity, SignInFragment, ImageUploaderService, ChangePasswordDialog.

1.2.2 Resources files资源文件

资源文件以小写+下划线组合进行命名

1.2.2.1 Drawable files可绘制文件

可绘制文件的命名协定:

资源类型前缀举例
Action barab_ab_stacked.9.png
Buttonbtn_btn_send_pressed.9.png
Dialogdialog_dialog_top.9.png
Dividerdivider_divider_horizontal.9.png
Iconic_ic_star.png
Menumenu_menu_submenu_bg.9.png
Notificationnotification_notification_bg.9.png
Tabstab_tab_pressed.9.png

图标的命名协定:

资源类型前缀举例
Iconsic_ic_star.png
Launcher iconsic_launcheric_launcher_calendar.png
Menu icons and Action Bar iconsic_menuic_menu_archive.png
Status bar iconsic_stat_notifyic_stat_notify_msg.png
Tab iconsic_tabic_tab_recent.png
Dialog iconsic_dialogic_dialog_info.png

选择器状态命名协定:

状态后缀举例
Normal正常_normalbtn_order_normal.9.png
Pressed按下_pressedbtn_order_pressed.9.png
Focused获取到焦点_focusedbtn_order_focused.9.png
Disabled不可用_disabledbtn_order_disabled.9.png
Selected选中_selectedbtn_order_selected.9.png
1.2.2.2 Layout files布局文件

布局文件应该匹配安卓组件,把对应顶级的组件名放在最前面。例如,我们需要给 SignInActivity 创建布局文件,那么命名应该是activity_sign_in.xml.

Component组件Class Name类名Layout Name布局名称
ActivityUserProfileActivityactivity_user_profile.xml
FragmentSignUpFragmentfragment_sign_up.xml
DialogChangePasswordDialogdialog_change_password.xml
AdapterView itemitem_person.xml
Partial局部layoutpartial_stats_bar.xml

当我们创建一个由Adapter产生的布局文件,例如去构建一个ListView。 在这种情况下,我们命名布局文件就要以item_ 开头。

注意,有些情况下这些规则的不太适用。比如,当创建用于其他布局的局部布局文件,在这种情况下,我们命名布局文件就要以partial_开头。

1.2.2.3 Menu files菜单文件

跟布局文件类似,菜单文件应该匹配组件名称。比如,如果我们定义一个在UserActivity菜单文件,那么我们应该命名为activity_user

比较好的做法是命名中不包括menu 字样,因这些文件已经存放在menu目录下面。

1.2.2.4 Values files 值文件

在值文件夹下的资源文件应该是 复数,例如strings.xml, styles.xml, colors.xml, dimens.xml, attrs.xml

License

Copyright 2015 Ribot Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值