Bottom Sheet fragment with a sticky header and a content recycler view

Overview

Sticky Header Bottom Sheet

A simple library to create a Bottom Sheet with a sticky header and a content recycler view.
The bottom sheet expands on scrolling the content recyclerview, and once it is fully expanded, the header sticks on the top while the recyclerview is still scrolling.

  

Adding dependencies:

if your gradle version is 7.0 or above : Add this to your settings.gradle (Project level):

dependencyResolutionManagement {
	repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
	repositories {
		....
		maven { url 'https://jitpack.io' }
	}
}

If your gradle version is below 7.0 : Add this to your build.gradle (Project level):

allprojects {
	repositories {
		....
		maven { url 'https://jitpack.io' }
	}
}

Add the dependencies in your app/build.gradle:

dependencies {
    ....
    implementation 'com.github.kshitijskumar:StickyHeaderBottomSheet:1.0.1'
}

Note: Databinding or Viewbinding is not supported yet

How to use the library

  1. Extend FeatureBottomSheet class with StickyHeaderBottomSheetDialogFragment
class FeatureBottomSheet : StickyHeaderBottomSheetDialogFragment()
  1. Implement abstract methods of the base class
(R.id.recyclerView) ?: throw IllegalStateException("Recyclerview not found") } ">
    override fun getContentView(): Int {
        return R.layout.fragment_feature_bottom_sheet
    }

    override fun getHeaderView(): View {
        return view?.findViewById<ConstraintLayout>(R.id.header) ?: throw IllegalStateException("Header view not found")
    }

    override fun getContentRecyclerView(): RecyclerView {
        return view?.findViewById<RecyclerView>(R.id.recyclerView) ?: throw IllegalStateException("Recyclerview not found")
    }
  1. Make sure you don't override onCreateView to inflate the layout for the bottom sheet as StickyHeaderBottomSheetDialogFragment handles inflating the right view itself. You can get the view in onCreateView from super method, then return the same view
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val v =  super.onCreateView(inflater, container, savedInstanceState)
        // do whatever you want to do
        return v
    }
  1. Your layout file should be primarily divided into 2 section, Header and Content (recycler view)
// header .... // content recyclerview ">
    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">

// header
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        ....

    </androidx.constraintlayout.widget.ConstraintLayout>

// content recyclerview
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@id/header"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:paddingVertical="20dp"
        android:clipToPadding="false"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Additionally

If in some use case you don't want the bottom sheet to expand on scrolling (suppose there are only 2-3 items in content recyclerview), in that case you can use this method,

    ....
    // after updating the list in content
    updateBottomSheetHeight(shouldMakeScrollable = false)
    // true to make the bottom sheet expand
You might also like...
A simple Floating Action Button that shows an anchored Navigation View
A simple Floating Action Button that shows an anchored Navigation View

Floating Navigation View A simple Floating Action Button that shows an anchored Navigation View and was inspired by Menu Material Fixed created by Tom

The idea of ResideMenu is from Dribbble 1 and 2. It has come true and run in iOS devices. iOS ResideMenu This project is the RefsideMenu Android version. The visual effect is partly referred to iOS version of ResideMenu. And thanks to the authors for the above idea and contribution. Animations for Android L drawer, back, dismiss and check icons
Animations for Android L drawer, back, dismiss and check icons

Material Menu Morphing Android menu, back, dismiss and check buttons Have full control of the animation: Including in your project compile 'com.balysv

:fire: The powerful and easiest way to implement modern material popup menu.
:fire: The powerful and easiest way to implement modern material popup menu.

PowerMenu 🔥 The powerful and easiest way to implement modern material popup menu. PowerMenu can be fully customized and used for popup dialogs. Downl

An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Simple and easy to use circular menu widget for Android.
Simple and easy to use circular menu widget for Android.

Deprecated This project is no longer maintained. No new issues or pull requests will be accepted. You can still use the source or fork the project to

A multicard menu that can open and close with animation on android
A multicard menu that can open and close with animation on android

MultiCardMenu A multicard menu that can open and close with animation on android,require API level = 11 Demo ##Usage net.wujingchao.android.view.

A menu consisting of icons (ImageViews) and metaball bouncing selection to give a blob effect. Inspired by Material design

Metaball-Menu A menu consisting of icons (ImageViews) and metaball bouncing selection to give a blob effect. Inspired by Material design ScreenShot Us

An Android Library that allows users to pull down a menu and select different actions. It can be implemented inside ScrollView, GridView, ListView.
An Android Library that allows users to pull down a menu and select different actions. It can be implemented inside ScrollView, GridView, ListView.

AndroidPullMenu AndroidPullMenu is an Open Source Android library that allows developers to easily create applications with pull menu. The aim of this

Releases(1.0.1)
Owner
Kshitij Kumar
Android dev and a B.Tech student from Maharaja Surajmal Institute of Technology, GGSIPU, New Delhi.
Kshitij Kumar
🚀 A very customizable library that allows you to present menu items (from menu resource and/or other sources) to users as a bottom sheet.

SlidingUpMenu A library that allows you to present menu items (from menu resource and/or other sources) to users as a bottom sheet. Gradle Dependency

Rasheed Sulayman 26 Jul 17, 2022
You can create awesome menus with bottom sheet experience in a few lines

You can create awesome menus with bottom sheet experience in a few lines

Mazen Rashed 19 Nov 1, 2022
Spinner with bottom sheet dialog for Android

This is a small library for spinner view with displaying options in bottom sheet dialog. This view doesn't improve or extend the default android Spinner. The library doesn't support any other types of showing menu, only bottom sheet dialog.

Oleg Nestyuk 23 Oct 19, 2022
Bottom Navigation widget component inspired by the Google Material Design Guidelines at https://www.google.com/design/spec/components/bottom-navigation.html

Material Bottom Navigation Library Lightweight Bottom Navigation library component inspired by the Google Material Design Guidelines at https://www.go

Alessandro Crugnola 1.4k Dec 18, 2022
Android library that provides the floating action button to sheet transition from Google's Material Design.

MaterialSheetFab Library that implements the floating action button to sheet transition from Google's Material Design documentation. It can be used wi

Gordon Wong 1.6k Dec 13, 2022
Spotify like android material bottom navigation bar library.

SuperBottomBar About Spotify like android material bottom navigation bar library. GIF Design Credits All design and inspiration credits belongs to Spo

Ertugrul 73 Dec 10, 2022
Suhuf is an android library that is used to build bottom sheets in an elegant way.

Suhuf is an android library that is used to build bottom sheets in an elegant way.

Rahmat Rasyidi Hakim 10 Nov 15, 2021
A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

AnimatedBottomBar A customizable and easy to use bottom bar view with sleek animations. Examples Playground app Download the playground app from Googl

Joery 1.2k Dec 30, 2022
An android custom view which looks like the menu in Path 2.0 (for iOS).

ArcMenu & RayMenu ArcMenu An android custom view which looks like the menu in Path 2.0 (for iOS). RayMenu About The user experience in Path 2.0 (for i

daCapricorn 1.3k Nov 29, 2022