问题
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