Praveen P.
Praveen P.

Reputation: 1106

Disable click animation effect in recyclerview items

I am trying to disable the animation on click events in recyclerview items but I should allow scrolling through the list. This is my current code, but it doesn't work because I can't scroll up and down. What am I missing?

binding.recyclerView.addOnItemTouchListener(object : RecyclerView.SimpleOnItemTouchListener() {
      override fun onInterceptTouchEvent(recyclerView: RecyclerView, motionEvent: MotionEvent) = false
    })

Upvotes: 1

Views: 570

Answers (1)

javdromero
javdromero

Reputation: 1937

You can simply remove the item animator altogether on your xml:

recyclerView.itemAnimator = null

Or by code after declaring and initializing your recyclerView:

recyclerView.setItemAnimator(null)

If that doesn't work, in your item.xml add to the parent layout:

android:focusable="false"
android:clickable="false"

Upvotes: 1

Related Questions