什么已被使用,content_main或Activity_main? [英] What has to be used, content_main or Activity_main?
问题描述
由于Android的工作室新的更新后,增加了XML文件带来了一些混乱。
虽然设置的setContentView的参数()
,其中XML已经被使用? Content_main或Activity_main?
如果我想添加一个布局文件(XML)我必须创建具有相同名称的两个文件?
虽然设置的setContentView,该XML有成为参数
类型? Content_main或Activity_main?
块引用>您应该使用
content_main.xml
来把你的观点,但通activity_main.xml中
作为参数传递给您的setContentView()
方法。
activity_main.xml中
是用来显示coordinatorLayout,tabLayout,floatingActionButton,viewPager等。
content_main.xml
是用来显示你的东西,即要显示给用户的东西。<一个href=\"http://stackoverflow.com/questions/33183107/difference-between-content-main-xml-and-activity-main-xml\">reference
如果我想添加一个布局文件(XML)做我必须创建具有相同名称的两个文件?
完全取决于您要创建布局的活动的性质。上面的差异将帮助你决定是否需要两个或一个。
Since after the new update in Android studio, the addition of the XML files has brought some confusion.
While setting the parameters for
setContentView()
, which XML has to be used? Content_main or Activity_main ?And if I want to add an Layout file (XML) do I have to create 2 files with the same names?
解决方案While setting the parameters for setContentView, which XML has to be typed ? Content_main or Activity_main ?
You should use
content_main.xml
to put your views but passactivity_main.xml
as the parameter to yousetContentView()
method.
activity_main.xml
is used to display coordinatorLayout, tabLayout, floatingActionButton, viewPager etc.
content_main.xml
is used to display your stuff i.e. what you want to display to users.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屋!