ScrollView drag items

Hello, I’m looking for a way to drag objects from a scrollView, I create the scroll, I add items but I can not drag them out of the scrollView, any ideas?

There are a number of ways to implement this, but in short you need to detect the touch event on the item to be dragged and work out if the touch needs to be passed to the scroll view. If it does, you can use takeFocus() on the scroll view to pass the touch event to the scroll view.

There are two common ways to detect dragging of items within a scroll view. First, you can check for touch motion cross-wise against the scroll direction of the scroll view. Secondly, you can simply wait a given time, check that the touch has not moved beyond a given threshold and begin the drag operation on the item.

In any situation, you will need to be careful about how you handle the drag operation. Passing the touch to the scroll view is relatively easy; Just call takeFocus() on the scroll view and make sure you don’t have any thing else still listening or responding to the same event. Actually dragging the item from the scroll view is a little trickier.

You might want to drag the item off the scroll view, which means the item needs inserting into another display group - probably something above the scroll view’s parent group. Alternatively, you might want to create a whole new object to be dragged, which would also need to be added to the high-level display group. This is so that the item being dragged is visible on top of the scroll view - you don’t want it passing underneath other items in the scroll view.

Finally, whichever item is being dragged off the scroll view, that item will need to handle the touch event itself, which means you might need to provide your own takeFocus(). This is more important if you’re creating a spawned item and not dragging the original item, but you need to think carefully about the process of grabbing something from the scroll view and how the touch event is managed. As with any test case, I highly recommend creating a very simple, sample application to try this out in and not building it for the first time in the intended app.

There are a number of ways to implement this, but in short you need to detect the touch event on the item to be dragged and work out if the touch needs to be passed to the scroll view. If it does, you can use takeFocus() on the scroll view to pass the touch event to the scroll view.

There are two common ways to detect dragging of items within a scroll view. First, you can check for touch motion cross-wise against the scroll direction of the scroll view. Secondly, you can simply wait a given time, check that the touch has not moved beyond a given threshold and begin the drag operation on the item.

In any situation, you will need to be careful about how you handle the drag operation. Passing the touch to the scroll view is relatively easy; Just call takeFocus() on the scroll view and make sure you don’t have any thing else still listening or responding to the same event. Actually dragging the item from the scroll view is a little trickier.

You might want to drag the item off the scroll view, which means the item needs inserting into another display group - probably something above the scroll view’s parent group. Alternatively, you might want to create a whole new object to be dragged, which would also need to be added to the high-level display group. This is so that the item being dragged is visible on top of the scroll view - you don’t want it passing underneath other items in the scroll view.

Finally, whichever item is being dragged off the scroll view, that item will need to handle the touch event itself, which means you might need to provide your own takeFocus(). This is more important if you’re creating a spawned item and not dragging the original item, but you need to think carefully about the process of grabbing something from the scroll view and how the touch event is managed. As with any test case, I highly recommend creating a very simple, sample application to try this out in and not building it for the first time in the intended app.