What controls whether the main layout file is "main.xml" or something else?
I was going through the tutorial in "Learning Android" where it suggested to rename the main layout file from "main.xml" to "status.xml". I only know I haven't seen this suggestion before (making the main layout file name more application-specific), but I don't know that there's anything particularly wrong with it.
However, I'm wondering, how 开发者_C百科does the build know to look for "main.xml", or "status.xml", for that matter. Does it just look for any layout file in the res/layout directory?
Look at your Activity and you will see a line like this:
setContentView(R.layout.main);
There is an auto-generated class called R.java in the gen directory which identifies all the resources in your application. So all the layout xml files in res/layout directory will be defined in R.java. setContentView associates the layout file with that particular Activity.
You select the XML to use by calling setContentView.
精彩评论