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

查看:19
本文介绍了什么是 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屋!

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