为什么我的comman导航darwerlayout和content.xml相互重叠

时间:2018-01-13 18:39:25

标签: android android-navigation-drawer

问题:为什么我的常用导航抽屉布局和content.xml相互重叠

我想使用include为所有多个活动实现通用导航抽屉。我为导航抽屉创建了一个单独的XML文件,并在其中包含工具栏代码。

Navigation.xml

这是我们包含工具栏和抽屉代码的导航部分。这里我们通过使用抽屉布局和循环视图实现简单的导航代码

        <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/navigation_Drawerlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:openDrawer="start">

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

            <android.support.design.widget.NavigationView
                android:id="@+id/navigation_View"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:fitsSystemWindows="true">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <include layout="@layout/navigation_headerview" />

                    <android.support.v7.widget.RecyclerView
                        android:visibility="gone"
                        android:id="@+id/navigationRecycleView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
                </LinearLayout>
            </android.support.design.widget.NavigationView>


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

        Toolbar.xml
        this the common toolbar for all the activities.the most uses of it we can easily reuse the code.in which I've simply use CoordinatorLayout and AppBarLayout inside it use toolbar layout with a title.so that I can show toolbar title with a toolbar.

        <?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.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/colorPrimary"
                    android:minHeight="?attr/actionBarSize"
                    app:titleTextColor="@android:color/white">

                    <!-- Screen title -->
                    <TextView
                        android:id="@+id/toolbarTitle"
                        style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text=""
                        android:textColor="@android:color/white"></TextView>
                </android.support.v7.widget.Toolbar>
            </android.support.design.widget.AppBarLayout>
        </android.support.design.widget.CoordinatorLayout>

        contents.xml
        this the content file where we define my code logic and implementation and also similar to all the activities which use the common navigation drawer

        <?xml version="1.0" encoding="utf-8"?>
        <FrameLayout
            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:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            tools:context=".Activities.EventsActivity"
            tools:showIn="@layout/toolbar"
            >

            <!-- Events -->
            <include
                layout="@layout/toolbar" />

            <android.support.v7.widget.RecyclerView
                android:layout_marginTop="55dp"
                android:id="@+id/events_recyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </FrameLayout>

0 个答案:

没有答案