A Parallax header for your RecyclerView using a CoordinatorLayour Behavior (Android Development)

The problem that is solved

The architecture of the solution

What is a custom behavior

The ParallaxHeaderBehavior behavior

  • override OnStartNestedScroll to indicate that we wish to receive scroll events for vertical scrolls (otherwise the below methods are not called)
  • overrides OnNestedPreScroll to scroll the header view first (when scrolling down) or scroll the recyclerview first (when scrolling up)
  • override OnNestedFling/OnNestedScroll as flings scroll events are not sent by the CoordinatorLayout. We simply redirect the call to OnNestedPreScroll.
  • override OnLayoutChild in which we add a top padding to the RecyclerView so our header view appears in the blank space left by this padding. Note that i’m also using a SwipeRefreshLayout here, so i moved down the indicator in the same code (with the same padding).

Good luck






Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Benjamin Mayrargue

Benjamin Mayrargue


More from Medium

How to Mute Audio and Adjust Volume During a Video Call in Android Using the Agora SDK

Two-Way Data Binding ,RecyclerView ,ViewModel,LiveData,MVVM and retrofit in kotlin

How to Submit your Android Application to Google Play

Top 7 Tips for How to Develop Android Apps Better.

How to Develope Android Apps Better