activity-(class).xml和content-(class).xml之间的区别?

时间:2016-03-15 20:25:31

标签: android xml

嗨=)我只是很好奇,当我在Android Studio中创建一个Android项目时,我相信我有最新版本的,有空白活动或其他任何主要活动,例如......这个主要活动附带了2个xml文件,activity-main.xml和content-main.xml 好吧,我有几个参考指南和教程书,所有人都说要导航到activity-main.xml来编辑实际应用程序的布局。但是activity-main.xml的内容包括:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="blahblahblah">

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_crime"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

我假设这只适用于浮动操作按钮附带的较新的Android版本,因为我可以看到的这个文件控制操作栏和操作按钮...但其他一切的应用程序布局实际上包含在内容中-main.xml 我只是好奇发生了将这些文件拆分成文件的原因?

1 个答案:

答案 0 :(得分:1)

据我所知,没有区别。 您可以删除这两个并继续使用您自己的'my-own-activity.xml'

这两件事需要:

  1. 您的xml文件包含xml标题
  2. 您在活动的onCreate()
  3. 的'setContent()'中设置了正确的xml文件

    修改:按照此处的建议:https://stackoverflow.com/a/32880945/1750013 显然,这两个XML用于创建更易读的代码,但在功能方面没有区别,即两者都是纯XML文件。