Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed navigation header in navigation drawer while scrolling through items

CURRENT STATE: NavigationDrawer with a NavigationHeader and NavigationMenu items. The items are large in number so scrolling is required in order to access the items towards the bottom.

REQUIREMENT: When scrolling down to the bottom, the NavigationHeader should stay fixed

Here's my activity_main layout file

<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_main"
    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"
    android:background="#00000000"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer"
    />

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

Here's my navigation_header_main layout file

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:background="#3d3b3b"

android:theme="@style/ThemeOverlay.AppCompat.Dark">

<android.support.v7.widget.AppCompatImageView
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:src="@drawable/categories"
    android:padding="1dp"
    />

</RelativeLayout>

P.S I am new to android dev. Please ask for more resources if required

like image 248
Parabola Avatar asked Dec 05 '22 00:12

Parabola


1 Answers

Found a workaround. Definitely not the most efficient one. Please suggest if anything could be done from here.

<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_main"
  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"
  android:background="#00000000"
  app:headerLayout="@layout/nav_header_main"
  app:menu="@menu/activity_main_drawer">

 <include layout="@layout/nav_header_main"

 <android.support.design.widget.NavigationView>

Definitely works. But the header layout is redundant

like image 98
Parabola Avatar answered May 08 '23 13:05

Parabola