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

查看:480
本文介绍了为什么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 :

创建这两个文件是为了使您的工作 EASIER .作为主文件,在坐标布局中包含诸如FAB, toolbar之类的内容.现在,您的内容文件是一个文件,您可以在其中创建视图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天全站免登陆