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

查看:205
本文介绍了什么已被使用,content_main或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 pass activity_main.xml as the parameter to you setContentView() 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.

reference

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天全站免登陆