导航抽屉(SlidingMenu)无法正常工作

时间:2016-02-12 06:43:37

标签: android navigation-drawer

我在我的Activity .xml中使用DrawerLayout如下:

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- The first child in the layout is for the main Activity UI-->
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:background="#09436B"
            android:elevation="6dp"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/toolbar"
            android:background="#F1F1F1"
            android:elevation="6dp"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:tabGravity="fill"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/tab_selected_text_color"
            app:tabTextColor="@color/tab_text_color" />


        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/tab_layout"></android.support.v4.view.ViewPager>

    </RelativeLayout>

    <!-- Side navigation drawer UI -->
    <LinearLayout
        android:id="@+id/layout_navigation_drawer"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <com.almabay.almachat.circularImageView.CircularImageView
                android:id="@+id/imgUser"
                android:layout_width="100dp"
                android:layout_height="100dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/txtNameUser"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/txtEmaiIDUser"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </LinearLayout>
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/margin10"></View>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txtProfile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/profile" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txtAccount"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/accounts" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txtNotification"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/notification" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txtContacts"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/contacts" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txtChats"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/chats" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txtHelp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/help" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/margin10" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txtLogout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/logout" />
        </LinearLayout>
    </LinearLayout>

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

但是我找到了正确的导航抽屉。没有显示汉堡包图标

ScreenShot

我想实现以下屏幕:

Scree to implement

请指导我在哪里做错。我知道在DrawerLayout里面有一个视图是屏幕的主要内容,另一个是导航抽屉项目。我研究了各种例子,表明我必须使用列表视图导航抽屉的项目,但我不能在这里使用列表视图,因为我必须修复我的设计。

1 个答案:

答案 0 :(得分:1)

我建议您使用导航视图(将其放在抽屉布局的底部)并将您的物品放入其中。

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start">

    <include layout="@layout/your navigation view layout"/>

</android.support.design.widget.NavigationView>
相关问题