android-layout - 为什么Android Studio会创建两个xml布局文件

标签 android-layout android-studio

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

为什么需要两个xml?默认将 activity_main 称为:setContentView(R.layout.activity_main),但我发现 setContentView(R.layout.content_main) 也可以。

这两种布局有什么关系?

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

谢谢

最佳答案

Why create 2 files :



创建这两个文件是为了让您的工作 更简单 .作为主文件包含你的东西,如 FAB, toolbar在坐标布局中。现在您的内容文件是一个文件,您可以在其中制作 View UI 而不会中断基本流程。我个人推荐这个。

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.



这些将工作,因为所有这些都是布局文件,因此可以设置为内容 View 。

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-layout - 为什么Android Studio会创建两个xml布局文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35564962/

相关文章:

android - java.util.zip.ZipException : duplicate entry: android/support/v4/accessibilityservice/AccessibilityServiceInfoCompatJellyBeanMr2. 类

android - 无法均匀缩放 9patch 图像

android - 如何在 android 中测量 View 或 View 组膨胀时间?

android - 无法启动 Android 虚拟 AVD 设备

android - TabLayout 的不同 tabMode

java - 在 Android Studio 中构建 Google Endpoints 后端时出现 403 禁止错误

java - 当前位置和搜索位置之间的道路/路线图

android - Android Studio中一致的Gradle错误

java - 异步任务 : class should be static or leaks might occur

android - Android Studio 中的 OpenCV