必须使用什么,content_main 或 Activity_main? [英] What has to be used, content_main or Activity_main?

查看:24
本文介绍了必须使用什么,content_main 或 Activity_main?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从Android Studio 新的更新之后,XML 文件的添加带来了一些混乱.

Since after the new update in Android studio, the addition of the XML files has brought some confusion.

在为setContentView() 设置参数时,必须使用哪个 XML?Content_main 或 Activity_main ?

While setting the parameters for setContentView(), which XML has to be used? Content_main or Activity_main ?

如果我想添加布局文件 (XML),是否必须创建 2 个具有相同名称的文件?

And if I want to add an Layout file (XML) do I have to create 2 files with the same names?

推荐答案

在设置setContentView的参数时,XML必须是打字?Content_main 还是 Activity_main ?

While setting the parameters for setContentView, which XML has to be typed ? Content_main or Activity_main ?

你应该使用 content_main.xml 来放置你的视图但是通过activity_main.xml 作为setContentView() 方法的参数.

You should use content_main.xml to put your views but pass activity_main.xml as the parameter to you setContentView() method.

activity_main.xml 用于显示 coordinatorLayout、tabLayout、floatingActionButton、viewPager 等

activity_main.xml is used to display coordinatorLayout, tabLayout, floatingActionButton, viewPager etc.

content_main.xml 用于显示您的内容,即您想向用户显示的内容.

content_main.xml is used to display your stuff i.e. what you want to display to users.

参考

如果我想添加一个布局文件 (XML),我是否必须创建 2 个文件同名?

And if I want to add an Layout file (XML) do I have to create 2 files with the same name ?

完全取决于您为其创建布局的活动的性质.上述差异将帮助您决定是需要两个还是一个.

Totally depends on the nature of the activity you are creating the layout for. The difference above will help you decide whether you need two or one.

这篇关于必须使用什么,content_main 或 Activity_main?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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