Michael P
Michael P

Reputation: 245

How to fix RecyclerView requiresFadingEdge and clipToOutline glitch

I have a RecyclervView with a rounded Drawable background and .clipToOutline = true in order to keep the overscroll animation inside the background. When I set requiresFadingEdge="vertical", there's a glitch where the fading edge is; example below. How can I fix this? The issue doesn't appear when I set .clipToOutline = false or when I don't have a fading edge, but I would like both of these effects. Thanks for the help.

enter image description here

You can see the issue in the bottom corners of the blue RecyclerView.

Upvotes: 2

Views: 556

Answers (1)

pina14
pina14

Reputation: 56

This can be fixed by setting a different layer type either in xml, or programatically when initialising your recyclerview:

XML

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layerType="hardware"
    ...

Programatically

recyclerView.setLayerType(VIEW.LAYER_TYPE_HARDWARE, null)

You can also use LAYER_TYPE_SOFTWARE, but it's better to use LAYER_TYPE_HARDWARE for performance reasons. Find out more about this 2 options in these docs:

Upvotes: 3

Related Questions