0

I'm trying to have a listView in my navigation drawer header. I have the list there and it populates fine, the only issue is that I can't scroll the list. It seems the nav drawer itself is intercepting the scroll action and not allowing me to scroll the ListView

nav_header_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="260dp"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical">

    <ListView
        android:id="@+id/myList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>

and the drawer

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

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

<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_drawer"
    app:menu="@menu/activity_drawer_drawer" />

If you need any more files, I can post

image here

Yonah Karp
  • 581
  • 7
  • 22

2 Answers2

2

You can customize navigation drawer as you want. design a separate layout say nav_layout.xml and in your activity_home.xml replace your navigation view with below code.

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

        <include
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            layout="@layout/nav_layout" />


    </android.support.design.widget.NavigationView>

Now open your nav_layout.xml and put below code.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="260dp"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical">

    <ListView
        android:id="@+id/myList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>

in this way you can customize navigation drawer as you want.

Abhishek Joshi
  • 361
  • 1
  • 7
  • 17
  • I used your answer and it was working great, until I realized the menu items (share, send) were gone. I've asked a new question [here](https://stackoverflow.com/questions/44689907/listview-in-navigationview-not-scrolling-navigationview-menu-disappearing). Any further help would be greatly appreciated! – Yonah Karp Jun 22 '17 at 04:25
  • hi still its not scrolling any idea? – Vijay May 07 '19 at 10:10
0

For the listview xml try adding one or both:

android:focusable="true" android:focusableInTouchMode="true"

I had to do this for buttons created in a listview which were not responding to touch events.