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

问题描述

由于Android的工作室新的更新后,增加了XML文件带来了一些混乱。

虽然设置的setContentView的参数(),其中XML已经被使用? Content_main或Activity_main?

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


解决方案

You should use content_main.xml to put your views but passactivity_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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:40