Most visited

Recently visited

DragStartHelper

public class DragStartHelper
extends Object

java.lang.Object
   ↳ android.support.v13.view.DragStartHelper


DragStartHelper是用于实现拖放支持的实用程序类。

它检测通常用于开始拖动的手势(长按任意输入源,单击并拖动鼠标)。

它还会跟踪拖动开始的屏幕位置,并帮助确定拖影的热点位置。

执行 DragStartHelper.OnDragStartListener开始拖动操作:

 DragStartHelper.OnDragStartListener listener = new DragStartHelper.OnDragStartListener {
     protected void onDragStart(View view, DragStartHelper helper) {
         View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view) {
             public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
                 super.onProvideShadowMetrics(shadowSize, shadowTouchPoint);
                 helper.getTouchPosition(shadowTouchPoint);
             }
         };
         view.startDrag(mClipData, shadowBuilder, mLocalState, mDragFlags);
     }
 };
 mDragStartHelper = new DragStartHelper(mDraggableView, listener);
 
Once created, DragStartHelper can be attached to a view (this will replace existing long click and touch listeners):
 mDragStartHelper.attach();
 
It may also be used in combination with existing listeners:
 public boolean onTouch(View view, MotionEvent event) {
     if (mDragStartHelper.onTouch(view, event)) {
         return true;
     }
     return handleTouchEvent(view, event);
 }
 public boolean onLongClick(View view) {
     if (mDragStartHelper.onLongClick(view)) {
         return true;
     }
     return handleLongClickEvent(view);
 }
 

Summary

Nested classes

interface DragStartHelper.OnDragStartListener

当检测到拖动开始手势时要调用的回调的接口定义。

Public constructors

DragStartHelper(View view, DragStartHelper.OnDragStartListener listener)

创建与指定视图关联的DragStartHelper。

Public methods

void attach()

将助手附加到视图。

void detach()

从视图中分离帮助器。

void getTouchPosition(Point point)

计算开始拖动操作的触摸事件的位置。

boolean onLongClick(View v)

处理长时间点击事件。

boolean onTouch(View v, MotionEvent event)

处理触摸事件。

Inherited methods

From class java.lang.Object

Public constructors

DragStartHelper

DragStartHelper (View view, 
                DragStartHelper.OnDragStartListener listener)

创建与指定视图关联的DragStartHelper。 新创建的帮助程序最初未附加到视图,必须明确调用attach()

Parameters
view View: A View
listener DragStartHelper.OnDragStartListener

Public methods

attach

void attach ()

将助手附加到视图。

这将取代以前存在的触摸和长按听众。

detach

void detach ()

从视图中分离帮助器。

这会将触摸和长按听众重置为 null

getTouchPosition

void getTouchPosition (Point point)

计算开始拖动操作的触摸事件的位置。

Parameters
point Point: The position of the touch event that started the drag operation.

onLongClick

boolean onLongClick (View v)

处理长时间点击事件。

Parameters
v View: The view that was clicked and held.
Returns
boolean true if the callback consumed the long click, false otherwise.

onTouch

boolean onTouch (View v, 
                MotionEvent event)

处理触摸事件。

Parameters
v View: The view the touch event has been dispatched to.
event MotionEvent: The MotionEvent object containing full information about the event.
Returns
boolean True if the listener has consumed the event, false otherwise.

Hooray!