2

How can i keep the Header of Navigation Drawer Fixed and the content below it scrolling?

What i want is that the header of the Navigation Drawer should be fixed ie non scrollable but the content part should scroll

How can i do that? Content of the navigation drawer is a menu file.

activity_main.xml

<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="match_parent"
android:orientation="vertical">


<android.support.design.widget.AppBarLayout
    android:id="@+id/view"
    android:elevation="10dp"
    app:elevation="10dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="scrollable"
        app:tabTextAppearance="@style/MyTabStyle">

    </android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>

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

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

    </android.support.v4.view.ViewPager>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_menu">
        <!---->


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

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

navigation header xml

<?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="120sp"
android:background="@color/colorPrimary"
android:gravity="bottom"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
     android:src="@drawable/app_icon" />
</LinearLayout>
akkk
  • 1,457
  • 4
  • 23
  • 41
  • add the view above your listview, so that in drawer two views will be added, the first view will be fixed and second view will be scrollable – Onkar Nene Jul 11 '16 at 12:02
  • This link might help you:http://stackoverflow.com/questions/30936493/android-navigation-view-scroll-the-menu-items-only-issue – Dhruvi Jul 11 '16 at 12:33
  • Try this solution is tested and working for me https://stackoverflow.com/questions/37122753/fixed-navigation-header-in-navigation-drawer-while-scrolling-through-items/45526213#45526213 – Deven Aug 05 '17 at 20:44

0 Answers0