命名约定 - m1688/Hirebird GitHub Wiki

  • 图层资源

    • Layout:用于contentview的layout文件命名:activity_<desc>.xml 其中,<desc>为Activity类名驼峰转成下划线,并去掉类名中的Activity(如果有的话)。如AboutActivity->activity_about.xml
    • Dialog命名:dialog_描述.xml,例如:dlg_hint.xml
    • PopupWindow命名:ppw_描述.xml,例如:ppw _info.xml
    • 列表项命名listitem_描述.xml,例如:listitem_city.xml
    • 包含项:include_模块.xml,例如:include_head.xml、include_bottom.xml
  • id管理

    • id集中存放到res/values/ids.xml,内容如下(通过“@id/about_ok”形式来使用):

      <resources>

      <item name="about_ok" type="id"/>

      <item name="search_key" type="id"/>

      </resources>

    • id命名

    <所在模块描述>_<资源用途描述>,如"ab_desc",<所在模块描述>不一定要某个activity、fragment等的全名,但所有该模块下的控件应该有统一的前缀。

  • 字符串命名

    除某些特殊情况外,最好不与控件关联,使用通用的名称。多个单词间用下划线分割:

      <?xml version="1.0" encoding="utf-8"?>
    
      <resources>
    
      <string name="ok">确定</string>
    
      <string name="app_name">招聘</string>
    
      <string name="cancel">取消</string>
    
      </resources>
    
  • 图片命名

    • 静态图片前缀_模块、前缀_模块_描述,例如:bg_main.png、ic_main_search.png
    • 动态图片前缀_模块_描述_状态、前缀_描述_状态,例如:btn_film_buy_n.png、btn_film_buy_p.png、btn_back_n.png.如果有多种形态如按钮等除外如btn_film_buy.xml(selector)

    http://bwlsq.img38.wal8.com/img38/394592_20131215155111/138720280101.jpg

    http://bwlsq.img38.wal8.com/img38/394592_20131215155111/138720280218.jpg

  • 颜色

    RGB值统一放到res/values/colors.xml,通用的颜色name为名称,不通用的可以根据模块控件定义,通过这种方式使用:“@color/white”如:

      <?xml version="1.0" encoding="utf-8" ?>
      <resources>
      <color name="black">#000000</color><!--黑色 -->
      </resources>
    
  • style.xml

    将layout中不断重现的style提炼出通用的style组件,放到res/values/styles.xml中,然后在控件中以style="@style/mystyle"这种形式使用。

  • 代码

    代码按照模块分类。

    • com.recruit.app.ui.common 公用UI
    • com.recruit.app.ui.job 职位UI
    • com.recruit.app.ui.me 个人中心UI
    • com.recruit.app.ui.resume 简历UI
    • com.recruit.app.service 服务接口
    • com.recruit.app.domain.model 数据模型
    • com.recruit.app.dao DAO
    • com.recruit.app.db 数据库操作类

    类命名

    • Activity以Act开头,后跟描述
    • Adapter以Apt开头,后跟描述
    • Dialog以Dlg开头,后跟描述
    • Fragment以Frg开头,后跟描述
    • Service以Srv开头,后跟描述

    代码中不出现中文,除了注释。

    第三方库的引用要慎重,会造成应用比较大。

  • 特殊问题特殊处理,没有想到的后续再补充

⚠️ **GitHub.com Fallback** ⚠️