簡體   English   中英

導航抽屜xml中的活動布局重疊

[英]Overlapping activity layouts in navigation drawer xml

這是我編寫的第一個應用程序,存在以下問題:我的activity_navigation_drawer如下所示:

<?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.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用作具有vertical方向的根布局。

 <?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以獲得一些其他功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM