How to enable Drag a Marker (Android Map Api v2) a

2019-06-27 22:36发布

I have a map with some markers. I set the listener for drag:

map.setOnMarkerDragListener(this);

But the drag is enable only after the user long press the marker. I want to enable drag immediately. Is there a way to do this with Android Maps (v2)?

1条回答
看我几分像从前
2楼-- · 2019-06-27 23:38

You can use Drag and Drop, with the Android drag/drop framework, you can allow your users to move data from one View to another view in the current layout using a graphical drag and drop gesture. The framework includes a drag event class, drag listeners and helper methods and classes.

A drag and drop operation starts when the user makes some gesture that you recognize as a signal to start dragging data. In response, your application tells the system that the drag is starting. The system calls back to your application to get a representation of the data being dragged. As the user's finger moves this representation (a "drag shadow") over the current layout, the system sends drag events to the drag event listener objects and drag event callback methods associated with the View objects in the layout.

You create a drag event listener object ("listeners") from a class that implements View.OnDragListener. You set the drag event listener object for a View with the View object's setOnDragListener() method. Each View object also has a onDragEvent() callback method. Both of these are described in more detail in the section The drag event listener and callback method.

查看更多
登录 后发表回答