-2

My recycler view is overlapping my navigation drawer. The following is my code to the layout-

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

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="com.theappsolutes.shaadi.activities.HomeScreen">

    <include layout="@layout/app_bar_main" android:layout_width="match_parent"
             android:layout_height="match_parent" />

    <android.support.v7.widget.RecyclerView
            android:id="@+id/card_recycler_view"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>


</RelativeLayout>

<android.support.design.widget.NavigationView android:id="@+id/nav_view"
                                              android:layout_width="wrap_content" android:layout_height="match_parent"
                                              android:layout_gravity="start" android:fitsSystemWindows="true"
                                              app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>

I want to place the recycler view in an activity with the navigation drawer on top. Please help.

My nav header goes like -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical"
android:gravity="bottom">

<TextView android:id="@+id/user_full_name" android:layout_width="match_parent" android:layout_height="wrap_content"
    android:paddingTop="@dimen/nav_header_vertical_spacing"
    android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

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

</LinearLayout>

And my main drawer goes like-

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<group android:checkableBehavior="single">
    <item android:id="@+id/nav_logout" android:icon="@drawable/ic_power_settings_new_black_36dp"
        android:title="@string/logout" />
</group>

</menu>
Ambuj Kathotiya
  • 369
  • 4
  • 18
  • 1
    Your drawer needs to be listed last within `DrawerLayout`. That is, move the `NavigationView` to after the `RecyclerView`. You should also put the `` and the `RecyclerView` in another `ViewGroup`, since you should really only have a single content `View`. – Mike M. Aug 26 '16 at 05:59
  • What do you mean by putting in another ViewGroup? I am new to Android. Please tell. – Ambuj Kathotiya Aug 26 '16 at 06:06
  • 1
    I mean, put them inside, for example, a vertical ``. [This post](http://stackoverflow.com/questions/26440879/how-do-i-use-drawerlayout-to-display-over-the-actionbar-toolbar-and-under-the-st) has an example of a proper `DrawerLayout` setup. In the accepted answer, your `` goes where the `` is, the `` goes right after that, and your `` goes in place of the last `` there, at the bottom. – Mike M. Aug 26 '16 at 06:10
  • Sir,I got the solution, I had a separate xml called content_main.xml,which had a relative layout. I just placed my recycler view inside that and it worked. Thanks a lot sir. – Ambuj Kathotiya Aug 26 '16 at 06:39

1 Answers1

2

This is my working version : You need other Layout (like here a RelativeLayout) in the DrawerLayout. And then you should include your AppBar

<?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"
    layout_height="wrap_content"
    layout_width="wrap_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="com.example.blablabla.MainActivity">

        <include
            android:id="@+id/app_bar"
            layout="@layout/app_bar"></include>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/newsList"
            android:layout_below="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal">

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


    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.example.blabla.NavigationDrawerFragment"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer"></fragment>
</android.support.v4.widget.DrawerLayout>

Here is the fragment for my Navigation: In This example the NavigationDrawer has a ImageView on the Top and a List with a Img and Text for each one.

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

    <LinearLayout
        android:id="@+id/linid"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="#0064a7"
        android:paddingLeft="20dp">

        <ImageView
            android:layout_width="240dp"
            android:layout_height="120dp"
            android:elevation="20dp"
            android:gravity="center_vertical"
            android:src="@drawable/zanderlogo" />
    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/drawerList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </android.support.v7.widget.RecyclerView>    
</LinearLayout>
Koss
  • 124
  • 2
  • 13