问题
Generally, when we want to load android layout we use setContentView(view)
in onCreate function. I saw another function getLayoutResource()
which get load layout too. I have read getLayoutResource, but I don't understand about it.
What is the different between them?
回答1:
I am not sure where you read about getLayoutResource()
as loading layout too? The getLayoutResource()
method gets the layout resource that will be shown as the View. The setContentView(view)
on the other hand sets the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.
So for instance, if you had invoked setContentView(R.layout.my_awesome_layout);
, then calling getLayoutResource()
should return the Integer identifier for R.layout.my_awesome_layout
;
You can read more on setContentView(android.view.View)
I hope this helps.
来源:https://stackoverflow.com/questions/38826131/what-is-the-different-between-setcontentview-and-getlayoutresource-in-android