What is the different between setContentView and getLayoutResource in android?

◇◆丶佛笑我妖孽 提交于 2019-12-24 07:28:35

问题


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

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