Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drag and Drop view outside of Recyclerview

What I want to achieve: I want to have a view inside a scrollable layout (Recyclerview with GridlayoutManager) with tiles (Views) in it. Dragging and dropping an item inside of the RecyclerView should adjust the position of the icon and swap with the other elements. When a drag starts, an icon above the RecyclerView will change to a trash icon and dragging the view to this icon will delete it from this RecyclerView.

Initial stateStarting to drag View5dragging View5 to trash iconView5 was deleted and other Views moved along

I tried this excellent tutorial, but I didn't find a way how to handle dragging outside of the Recyclerview as the ItemTouchHelper.Callback uses only Recycler.ViewHolder elements as possible targets.

The method interpolateOutOfBoundsScroll() gives feedback if the view moves out of the boundaries, but will only give back the total size that is offscreen, but no coordinates. Also, trying to drag the view out of the Recyclerview always results in cutting of the View where it passes the borders of the Recyclerview.

Does anyone have an idea how I could achieve this effect?

like image 320
Eve Avatar asked Jan 27 '16 13:01

Eve


People also ask

How to drag and drop RecyclerView Android?

Drag and Drop can be added in a RecyclerView using the ItemTouchHelper utility class. Following are the important methods in the ItemTouchHelper. Callback interface which needs to be implemented: isLongPressDragEnabled - return true here to enable long press on the RecyclerView rows for drag and drop.

How do I move items in RecyclerView?

Android Swipe To Delete. Swipe to delete feature is commonly used to delete rows from a RecyclerView. In order to implement Swipe to delete feature, we need to use the ItemTouchHelper utility class.


1 Answers

You can achieve this simply by set this attribute for the parent of the RecyclerView:

    android:clipChildren="false"

Edit: thank Adam Katz, I don't know why but sometimes you have to add this to the RecyclerView to make it work:

    android:clipToPadding="false"
like image 126
Hai nguyen thanh Avatar answered Oct 07 '22 21:10

Hai nguyen thanh