Home » Android » Android – Constrain Drag and Drop to a Bounding Box

Android – Constrain Drag and Drop to a Bounding Box

Posted by: admin June 15, 2020 Leave a comment

Questions:

The default behavior of drag and drop on Android apparently allows the DragShadow to be dragged anywhere on the screen.

I’d like to limit the area in which it can be dragged – either to a specified bounding box, or to a the bounds of a particular view.

I see that I can monitor the drag location with onInterceptTouchEvent, but I don’t see any way to modify the drag location.

Has anyone done this successfully?

EDIT:
Since I got no answers here, and never did find any other suitable answer, I wrote my own implementation. It doesn’t use the drag-and-drop api, it simulates it instead.
See https://github.com/rfreedman/android-constrained-drag-and-drop-view

How to&Answers: