0

I am extending RecyclerView.ItemDecoration to define a class that enables a RecyclerView to make header view's sticky when they are at the top of the RecyclerView. For this, I need to override onDrawOver() to draw the sticky header , since I need to draw the sticky header on top of all the other RecyclerView view's. This has the unfortunate side effect of also drawing the sticky header on top of the RecyclerView's scrollbar. I am wondering if there is some way I can easily get the RecyclerView to draw it's scrollbar over this sticky header?

I've tried doing the following already:

  • Mess around with android:scrollbarStyle XML tag on RecyclerView. Setting this to outsideOverlay does not draw the scrollbar over the sticky header.
  • Move sticky header drawing logic to onDraw() instead of onDrawOver(). Doing this draws the sticky header underneath the scrollbar, but also draws it underneath the RecyclerView's other views.

Any feedback is helpful. Thanks.

David Read
  • 1,089
  • 1
  • 9
  • 23
  • If I understand the problem, since you are drawing the header, can't you just make it narrower by the width of the scrollbar? – Cheticamp Dec 28 '22 at 21:25
  • @Cheticamp Unfortunately, this is not an option. The header has a background color different from the root layout background. And the header takes the full width of the screen. – David Read Dec 29 '22 at 16:07
  • 1
    That's unfortunate. The scrollbars are drawn along with all the other _RecyclerView_ stuff and there is no hook to draw in between the item views and the scrollbar. Consider moving the scrollbar outside of the _RecyclerView_ or starting the scrollbar below the header (the top below the header.) – Cheticamp Dec 29 '22 at 17:30

0 Answers0