什么是 setContentView(R.layout.main)? [英] What is setContentView(R.layout.main)?
问题描述
我知道它与应用程序布局有关,但我什么时候必须使用它?我试图寻找一个解释这种方法的链接,但我找不到它.提前谢谢你!
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 in advance!
推荐答案
在 Android 中,视觉设计存储在 XML 文件中,每个 活动 与设计相关联.
In Android the visual design is stored in XML files and each Activity is associated to a design.
setContentView(R.layout.main)
R
表示资源
layout
表示设计
main
是你在res->layout->main.xml
每当您想要更改 Activity 的当前外观或从一个 Activity 移动到另一个 Activity 时,新 Activity 都必须具有要显示的设计.我们调用 setContentView
在 onCreate 中,以所需的设计作为参数.
Whenever you want to change the current look of an Activity or when you move from one Activity to another, the new Activity must have a design to show. We call setContentView
in onCreate with the desired design as argument.
这篇关于什么是 setContentView(R.layout.main)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!