Search code examples
androidandroid-recyclerviewgrid-layoutandroid-gridlayoutgridlayoutmanager

Is there a way to hold a particular element of a recyclerview on the top?


I am using a recyclerView, with a GridLayoutManager layout.

The recycler view contains 2 types on ViewHolders, one having span size equal to 3 in order to separate different types of grid elements and one of size equal to one.

What i want is to be able to hold always on the top one of the view holders of the size 3 (depending on the horizontal scroll position), like shown in the image below.

Does anyone has any idea how to do it? If it is possible i would want to avoid to create a custom layout, is there an easier way to do it?

grid layout exemple


Solution

  • You can check this github project StickyHeaders

    You can use directly this and import it as a dependency or you can look at the code and try to implement your own "sticky" header.