为什么Android Studio会创建两个xml布局文件 [英] Why Android Studio creates two xml layout files

查看:76
本文介绍了为什么Android Studio会创建两个xml布局文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

eClipse 只创建了一个 acitivity_main.xml 文件,而 Android studio 会创建两个 xml 布局文件.acitivity_main.xml 的默认布局是 CoordinatorLayout,但 content_main.xml 的默认布局是 RelativeLayout.

The eClipse only creates one acitivity_main.xml file, but Android studio creates two xml layout files. The default layout for acitivity_main.xml is the CoordinatorLayout but for content_main.xml is RelativeLayout.

为什么需要两个xml?默认是将 activity_main 引用为:setContentView(R.layout.activity_main),但我发现 setContentView(R.layout.content_main) 也有效.

Why need two xmls ? The default is to refer activity_main as: setContentView(R.layout.activity_main), but I find setContentView(R.layout.content_main) also works.

这两种布局有什么关系?

What is the relationship between these two layouts ?

如果我将按钮视图拖放到 content_main.xml 或将按钮视图拖放到 activity_main.xml 有什么区别?

Is there any difference If I drop a button view to the content_main.xml or I drop a button view to activity_main.xml ?

谢谢

推荐答案

为什么要创建 2 个文件:

Why create 2 files :

创建这 2 个文件是为了让您的工作更轻松.作为主文件,在坐标布局中包含诸如 FAB、工具栏 之类的东西.现在您的内容文件是您可以在不中断基本流程的情况下制作视图 UI 的文件.我个人推荐这个.

These 2 files are created to make your work EASIER. As main file contain your stuff like FAB, toolbar in Coordinate layout. Now your content file is file in which you can make UI of view without interrupting the basic flow. I personally recommend this.

为什么需要两个xml?默认是将 activity_main 引用为:setContentView(R.layout.activity_main),但我发现setContentView(R.layout.content_main) 也有效.

Why need two xmls ? The default is to refer activity_main as: setContentView(R.layout.activity_main), but I find setContentView(R.layout.content_main) also works.

这些将起作用,因为毕竟这些都是布局文件,因此可以设置为内容视图.

These will work as after all these are layout files so can set as content view.

如果我将按钮视图拖放到 content_main.xml 或将按钮视图拖放到 activity_main.xml 有什么区别?

Is there any difference If I drop a button view to the content_main.xml or I drop a button view to activity_main.xml ?

完全没有区别.

这篇关于为什么Android Studio会创建两个xml布局文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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