Android in Navigation Drawer when I click anywhere drawer closes

天涯浪子 提交于 2019-11-28 02:13:52

I had the same problem once.

I had a RecyclerView NavigationDrawer and by just moving the Navigation code to the bottom of the xml file my problem got solved.

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

//some code here for the body of your activity

</RelativeLayout>


<android.support.v7.widget.RecyclerView
    android:id="@+id/RecyclerView"
    android:layout_width="350dp"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:background="#ffffff"
    android:scrollbars="vertical">

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

hope it works for you too...

For more explanation,

<ListView
        android:id="@+id/listViewDrawer"
        android:layout_width="240dp"
        android:layout_gravity="start"
        android:layout_height="match_parent"
        android:background="#fff"
        android:padding="3dp"
        android:choiceMode="singleChoice"
        android:dividerHeight="1dp"
        android:divider="@android:color/transparent">
    </ListView>

Is going to be your Content and other contents gonna be your NavigationDrawer actually.

Please see how it works:

http://developer.android.com/training/implementing-navigation/nav-drawer.html

Which said:

the following layout uses a DrawerLayout with two child views: a FrameLayout to contain the main content (populated by a Fragment at runtime), and a ListView for the navigation drawer.

And use NavigationDrawer which that comes from with new SupportLibrary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!