2

I have a pinned ItemDecoration (a header section) added before first (top) child of the RecyclerView.

When I scroll the RecyclerView, first item goes behind the header section. Since the section is transparent it looks like that section and first item get overlapped.

How can I clip the RecyclerView so that the overlapping does not happen?

enter image description here

Yogesh Rathod
  • 111
  • 1
  • 8
  • can you post a screenshot of what you mean? It's difficult to imagine what you mean – Kushan Apr 09 '18 at 11:09
  • I have added a .gif file in the question above. – Yogesh Rathod Apr 09 '18 at 11:54
  • please post your layout file too. I have a solution in mind, just want to be sure that what i think is correct – Kushan Apr 09 '18 at 11:57
  • @Kushan - Layout file does not have any special code. It is just a recyclerView with TextView items. The header texts shown above in red color (e.g. A, B, C etc.) are added using ItemDecorations. Thank you. – Yogesh Rathod Apr 09 '18 at 12:04
  • Yea but since A is static i was wondering if its a separate view and not a part of the recyclerview – Kushan Apr 09 '18 at 12:07
  • A is not static, it is added dynamically as itemDecoration when the initial letter of the item view changes. Hence A is added before all the items which start with A, and then B, etc. – Yogesh Rathod Apr 09 '18 at 12:18

1 Answers1

3

I assume that your ItemDecoration is using DrawOver() for the sticky header. Try setting a top padding to the RecyclerView that has a height equal to the height of your header android:paddingTop="somedp" and set android:clipToPadding="true". See this Stack Overflow answer for a good description of clip to padding.

You may have to adjust how your item decoration is drawn but this should prevent your items from sliding under the header.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131