Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 导航抽屉xml中的重叠活动布局_Java_Android_Navigation_Drawer - Fatal编程技术网

Java 导航抽屉xml中的重叠活动布局

Java 导航抽屉xml中的重叠活动布局,java,android,navigation,drawer,Java,Android,Navigation,Drawer,这是第一个应用程序I程序,我有以下问题:我的活动\u导航\u抽屉如下所示: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

这是第一个应用程序I程序,我有以下问题:我的活动\u导航\u抽屉如下所示:

<?xml version="1.0" encoding="utf-8"?>
  <android.support.v4.widget.DrawerLayout 
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

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

  <android.support.design.widget.NavigationView
      android:id="@+id/nav_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="start"
      android:fitsSystemWindows="true"
      app:headerLayout="@layout/nav_header_navigation_drawer"
      app:menu="@menu/activity_navigation_drawer_drawer" />

</android.support.v4.widget.DrawerLayout>

在这个xml文件中,我包含了我的appbar和我将在这个addbar下添加的内容。不幸的是,内容与整个appbar重叠(换句话说,我包含的两个布局是重叠的)

appbar.xml:

<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout 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="wrap_content"
    tools:context="...NavigationDrawerActivity">

    <android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      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>
</RelativeLayout>

content.xml:

<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout 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"
  app:layout_behavior="@string/appbar_scrolling_view_behavior"
  tools:context="...NavigationDrawerActivity">

  <include layout="@layout/activity_function_overview" />
</RelativeLayout>


我在这里做错了什么?

appbar.xml
中,使用
LinearLayout
作为根布局,使用
垂直方向

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout 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="wrap_content"
      android:orientation="vertical"
      tools:context="...NavigationDrawerActivity">

      <android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          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>

     <!-- Your content layout here -->

</LinearLayout>


仅供参考,您还可以使用android.support.design.widget.CoordinatorLayout来获得一些额外功能。

您是指CoordinatorLayout而不是LinearLayout?是的,您也可以使用android.support.design.widget.CoordinatorLayout而不是LinearLayout