什么是setContentView(R.layout.main)? [英] What is setContentView(R.layout.main)?

查看:148
本文介绍了什么是setContentView(R.layout.main)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它与App布局有关,但是什么时候必须使用它呢? 我试图寻找一个解释该方法的链接,但找不到. 预先谢谢你!

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

每当您要更改活动的当前外观或从一个活动转到另一个活动时,新的活动都必须具有要显示的设计.我们在onCreate中将 setContentView 称为所需的设计作为参数.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆