Home » Android » android – ItemTouchHelper with RecyclerView in NestedScrollView: Drag scrolling not work

android – ItemTouchHelper with RecyclerView in NestedScrollView: Drag scrolling not work

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have implemented ItemTouchHelper like descriped in this articel:
https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-b9456d2b1aaf#.k7xm7amxi

All works fine if the RecyclerView is a child of the CoordinatorLayout.

But if the RecyclerView is a child of NestedScrollView in CoordinatorLayout, the drag scrolling not working anymore.
Draging an item and move it to the top or bottom of the screen, the RecyclerView not scrolling like it do if its not a child of NestedScrollView.

Any ideas?

How to&Answers:

You have to disable the nestedScrolling for the recyclerView:

recyclerView.setIsNestedScrollingEnabled(false);

Answer:

android:descendantFocusability=”blocksDescendants”

add in NestedScrollView and add

android:focusableInTouchMode=”true”

in child layout it look like below

   <androidx.core.widget.NestedScrollView 
        android:descendantFocusability="blocksDescendants"> 

    <androidx.constraintlayout.widget.ConstraintLayout
        android:focusableInTouchMode="true">
        </androidx.constraintlayout.widget.ConstraintLayout> 

</androidx.core.widget.NestedScrollView>

check this github repo
https://github.com/khambhaytajaydip/Drag-Drop-recyclerview