Android: capital letter in filename of xml file, and the rule of naming a xml file

萝らか妹 提交于 2019-12-11 12:41:26

问题


It's ok to use capital letter in java file name in android project, but captial letter is not allowed in xml file name. What is the profit of this design?

I used to name xml file like this:activity_xxx. Is there any suggestion or rule in naming?


回答1:


It seems to be no official answer to this question. Resources are defined automatically in R.java. As an example, if you have a layout named activity_test then it will generate public static final int activity_test=0x7f040034; in R.java.

That generation doesn't follow android naming conventions for the constants. (See)

In my opinion, the Android dev team choosed to avoid this convention in this generated file in order to speed up the typing of the resource names (it is easier to type a lowercase letter than a capital letter)

If a project is created on Android Studio, the basic resources are prefixed by "activity_" for activities, "fragment_" for fragments, "menu_" for menues so it seems to be right way to write an xml filename.



来源:https://stackoverflow.com/questions/31958786/android-capital-letter-in-filename-of-xml-file-and-the-rule-of-naming-a-xml-fi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!