如何在工具栏下面设置NavitagionView?

时间:2016-03-20 18:08:42

标签: android navigation-drawer

我有自定义工具栏和导航视图。但是当我打开navigationview时,它看起来全屏。我想要它在工具栏下面。我该如何解决?这是我的activity_main.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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/container_app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <include --> MY CUSTOM TOOLBAR
            android:id="@+id/app_bar"
            layout="@layout/app_bar" />

        <FrameLayout
            android:id="@+id/flContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <it.neokree.materialtabs.MaterialTabHost
            android:id="@+id/materialTabHost"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_below="@+id/app_bar"
            app:accentColor="@color/colorPrimaryLight"
            app:hasIcons="true"
            app:iconColor="@android:color/white"
            app:materialTabsPrimaryColor="#009688" />
   </LinearLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_below="@+id/materialTabHost"
        android:layout_weight="1" />
</LinearLayout>

<android.support.design.widget.NavigationView
    app:theme = "@style/NavigationViewStyle"
    android:id="@+id/nvView"
    android:layout_width="250dp"
    app:itemIconTint="@color/colorPrimaryDark"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#fff"
    app:menu="@menu/drawer_view" />

我在工具栏下面尝试了几种显示导航工具的方法,但我每次都遇到错误。请帮忙吗?

1 个答案:

答案 0 :(得分:0)

在顶部使用LinearLayout或Relative Layout,并将你的drawerlayout置于你想要的顶部(工具栏,标签等)之下。并将你的内容放在你的抽屉布局中。

 <LinearLayout
        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">

       <LinearLayout
            android:id="@+id/container_app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <include --> MY CUSTOM TOOLBAR
                android:id="@+id/app_bar"
                layout="@layout/app_bar" />

            <it.neokree.materialtabs.MaterialTabHost
                android:id="@+id/materialTabHost"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:layout_below="@+id/app_bar"
                app:accentColor="@color/colorPrimaryLight"
                app:hasIcons="true"
                app:iconColor="@android:color/white"
                app:materialTabsPrimaryColor="#009688" />
       </LinearLayout>

        <android.support.v4.widget.DrawerLayout
            android:id="@+id/drawer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true"
            android:focusableInTouchMode="true">

            <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@+id/materialTabHost"
            android:layout_weight="1" />


            <android.support.design.widget.NavigationView
                android:id="@+id/navView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:background="@android:color/white"
                app:headerLayout="@layout/nav_header"
                app:menu="@menu/menu_drawer" >
        </android.support.design.widget.NavigationView>


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

    </LinearLayout>