问题描述
通常,当我们要加载android布局时,我们在 onCreate 函数中使用setContentView(view)
.我看到了另一个函数getLayoutResource()
,它也获得了加载布局.我已阅读 getLayoutResource ,但我不理解关于它.
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.
推荐答案
我不确定您在哪里也读到了关于getLayoutResource()
的加载布局? getLayoutResource()
方法获取布局资源,该资源将显示为视图".另一方面,setContentView(view)
从布局资源中设置活动内容.资源将被放大,将所有顶级视图添加到活动中.
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.
例如,如果您调用了setContentView(R.layout.my_awesome_layout);
,则调用getLayoutResource()
应该返回R.layout.my_awesome_layout
的整数标识符;
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
;
您可以在 setContentView( android.view.View)
我希望这会有所帮助.
这篇关于android中的setContentView和getLayoutResource有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!