布局文件命名约定? [英] Layout files naming conventions?

查看:94
本文介绍了布局文件命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是一些布局文件命名约定的人都来了。

我还没有发现任何在网上,但想过使用以下约定。

什么大家觉得呢?

   -  activity_ *
 - 对话_*
  -  list_item_ *
 

这就是我一直与到目前为止的工​​作。

另外,怎么样针对其布局活动的命名?例如:

   - >水库
     - >布局
         - > activity_about_us.xml
 - > SRC
     - >活动
         - > AboutUs.java
 

解决方案

奇怪的是,试图谷歌这个问题带来的只是这个页面,因为有意义的结果... 在过去的半年,我使用的命名与你相似,但更短的prefixes约定。例如: 对于活动,显示关于我们页面:

类名 ActAboutUs 。 prefixing类是一种矫枉过正,但它明确区分活动课从别人。起初我用所有活动单独的目录(类似于你的方法),但一段时间后,我意识到,对于较大的应用程序可能最好是组在目录中按功能不是由超类(即活动)。这是我更容易在单个目录中工作,例如 / src目录/设置/ 当我工作的设置。这样一来,我需要所有的Java文件都在一个目录,所以我不必再四处流浪:

  /src/settings/ActSettingsGlobal.java
/src/settings/ActSettingsNet.java
/src/settings/Settings.java
/src/settings/SettingsDBAdapter.java
/ src目录/设置/等...
 

这方法也有助于分割在不同的开发人员的工作,即每一个工作在自己的目录在不同的功能,因此在对方的脚没有步: - )

有些人preffer后缀,但我发现他们的用处不大。 prefixes有助于集团的事情字母像上面的例子:法* preFIX首先进行排序,因此所有活动都方便地在上面

我甚至考虑使用法_ 为preFIX哪个更可读,虽然它与Java命名约定冲突......

布局文件名 act_about_us.xml 。在 RES /布局/ 我们没有奢侈品子目录中这是相当可惜这么一群事物的唯一方法是使用适当的preFIX像行为_ DLG _ 等等...

字符串ID <字符串名称=act_about_us_dlg_help1_title...... string.xml 是我们拥有的大多数问题与重复名称 S中的位置。这是很容易创建副本,如果命名约定如 activity_element_item 不被使用。它增加了很多额外的打字,但它可以节省你从很多混乱以后。 对于全局(应用广泛)的字符串,我们使用preFIX 全球_,例如 global_btn_ok global_msg_no_inet_conn 。通常我们应该有一个人负责所有全球_ 字符串,所以如果有人需要新的字符串或更改他需要与他同步,以避免造成混乱。

(现在我认识到 activity__element__item (两个下划线)比 activity_element_item 更清晰可读)

总之,我还是无法摆脱的感觉,有什么错我的做法,因为我无法相信,谷歌开发者创造了这样一个不方便的框架,当谈到与文件,身份证,名字的时候,等等...

What are some layout file naming conventions people have come up with.

I haven't found anything online, but thought about using the following convention.

What does everyone think?

 - activity_* 
 - dialog_*
 - list_item_*

That's all I have worked with so far.

Also, what about the naming of the activity against its layout? For example:

-> res
    -> layout
        -> activity_about_us.xml
-> src
    -> activity
        -> AboutUs.java

解决方案

Strangely enough, trying to google this question brings only this page as meaningful result... For the past half year I am using naming convention similar to yours but with shorter prefixes. For example: For activity that shows "About us" screen:

Class name: ActAboutUs. Prefixing class is kind of overkill but it clearly distinguishes activity classes from the others. Initially I used separate directory for all the activities (similar to your approach) but after some time I realized that for bigger apps may be it is better to group in directories by feature than by superclass (i.e. Activity). It is easier for me to work in single directory for example /src/settings/ when I work on Settings. That way all java files that I need are in a single dir so i don't have to wander around:

/src/settings/ActSettingsGlobal.java
/src/settings/ActSettingsNet.java
/src/settings/Settings.java
/src/settings/SettingsDBAdapter.java
/src/settings/etc...

This approach also helps to split the work among different developers, i.e. each one is working in his own dir on separate feature so no stepping on each other's feet :-).

Some people preffer suffixes but I found them less useful. Prefixes help to group things alphabetically like in the example above: Act* prefix is sorted first so all activities are conveniently at the top.

I am even considering of using Act_ as a prefix which is more readable although it is in conflict with java naming conventions...

Layout filename: act_about_us.xml. In res/layout/ we don't have the "luxury" of subdirs which is quite unfortunate so the only way to group things is using appropriate prefix like act_, dlg_, etc...

String IDs: <string name="act_about_us_dlg_help1_title" ... string.xml is the place where we have most problems with duplicate names. It is very easy to create duplicates if naming convention like activity_element_item is not used. It adds a lot of additional typing but it saves you from a lot of confusion later on. For global (application wide) strings we use prefix "global_", for example global_btn_ok, global_msg_no_inet_conn. Usually we make one person responsible for all global_ strings so if someone needs new string or change he needs to sync with him in order to avoid creating a mess.

(now I am realizing that activity__element__item (two underscores) is more clear and readable than activity_element_item)

All in all I still can't get rid of the feeling that there is something wrong with my approach because I can't believe that google devs created such an inconvenient framework when it comes to working with files, IDs, names, etc...

这篇关于布局文件命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆