如何启用单点触摸后拖动标记(Android Map Api v2)? [英] How to enable Drag a Marker (Android Map Api v2) after a single Touch?

查看:163
本文介绍了如何启用单点触摸后拖动标记(Android Map Api v2)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张地图上有一些标记。我将侦听器设置为拖动:

  map.setOnMarkerDragListener(this); 

但是只有在用户长按标记后才能启用拖动。我想立即启用拖动。有没有一种方法可以在Android Maps(v2)中执行此操作?

解决方案

您可以使用 拖放 ,使用Android拖放框架,您可以允许用户使用图形拖放手势将数据从一个View移动到当前布局中的另一个视图。该框架包括一个拖拽事件类,拖拽侦听器和帮助器方法和类。



当用户做出一些手势,并将其识别为开始拖动数据。作为响应,您的应用程序会告诉系统拖动开始。系统回调您的应用程序以获取被拖动数据的表示。当用户的手指将此表示(拖影)移动到当前布局上时,系统将拖动事件发送到拖动事件侦听器对象,并拖动与 View 对象。



创建一个拖动事件侦听器对象(侦听器)来自实现 View.OnDragListener 。您设置与浏览对象的 setOnDragListener()方法。每个视图对象还具有 onDragEvent()回调方法。这两个部分在拖动事件侦听器和回调方法


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)?

解决方案

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.

这篇关于如何启用单点触摸后拖动标记(Android Map Api v2)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆