What is setContentView(R.layout.main)?

后端 未结 6 1312
滥情空心
滥情空心 2020-11-29 08:07

I understand that it has to do with the App layout, but when do I have to use it? I tried to look for a link that explained this method, but I couldn\'t find it. Thank you i

6条回答
  •  心在旅途
    2020-11-29 08:40

    As per the documentation :

    Set the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.

    Your Launcher activity in the manifest first gets called and it set the layout view as specified in respective java files setContentView(R.layout.main);. Now this activity uses setContentView(R.layout.main) to set xml layout to that activity which will actually render as the UI of your activity.

提交回复
热议问题