SimpleCallback for dragging view is not working, when i try to move top to bottom and bottom to top dragging item with ItemTouchHelper

30 views Asked by At

my RecyclerView scrolls not working top to bottom and bottom to top when i try to dragging. You can see the below code

i'm using xml like this

`

 <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rvDraggable"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/dp_16"
                    android:layout_marginEnd="@dimen/dp_16"
                    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/cardViewSeatWise" />
            </LinearLayout>
        </androidx.core.widget.NestedScrollView>

`

1

There are 1 answers

0
protaiyabali On

I got a solution: So the issues was that my layout

If you are using NestedScrollView just remove and instead of using other layouts use ConstraintLayout

Steps:

Use ConstrainLayout and RecylerView like this:

<androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvDraggable"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_0"
            android:layout_marginStart="@dimen/dp_16"
            android:layout_marginEnd="@dimen/dp_16"
            android:scrollbarStyle="outsideOverlay"
            android:scrollbars="none"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>

Note- you can also try to use:

  • viewBinding.recycler.setHasFixedSize(true)

  • If you are using notifyDataSetChanged() so just replace it by notifyItemMoved() in onMove() method