Dragging and dropping Android Gallery images

I am working on an application that allows users to order items from the Gallery widget. The user must be able to select an order from the Gallery widget. Orders should be displayed as images in the Gallery, and the user should be able to drag and drop the image and place it on the order button.

I am stuck with a drag part. How to drag and drop images using Gallery widget in Android?

+6
source share
2 answers

I never did this, so I can’t say for sure, but here is how I would approach the problem:

I would expand the existing gallery. Then override the onDown method or something similar to determine which image is touching.

Then I would display a new image with the image where the finger is located, which listens to the moved event movement.

and then when you click the button, you can check where the component fell.

-

You might also get the idea to write your own quick access gallery on the scroll bar, so you have a lot of control over the events;)

Greetings

Jason

+1
source

One approach is to expand the gallery and implement AdapterView.OnItemClickListener.

Your drag and drop action can be implemented as:

@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (!view.isTouched()) { return false; } customDragController.startDrag(view, this, view, CustomDragController.MOVE); return true; } 

For a more complete example of how this can be implemented, including customDragController, check out this github project.

+1
source

Source: https://habr.com/ru/post/899771/


All Articles