我使用view.startDrag()开始拖动操作.在拖动时,会在OnDragListener中接收事件.我也使用DragShadowBuilder在拖动时显示View B的最后一个图像.
有没有办法停止或取消或中止某些外部事件或操作的拖动?例如,有2个视图,视图A和视图B,我在视图A上拖动视图B.在拖动时,由于某些外部事件或操作,我想取消拖动操作或取消OnDragListener(不删除我的手指视图B).
DragShadowBuilder的代码片段:
DragShadowBuilder shadowBuilder = new DragShadowBuilder(view) { @Override public void onDrawShadow(Canvas canvas) { canvas.drawBitmap(b,new Paint()); super.onDrawShadow(canvas); } }; boolean dragSuccess = false; dragSuccess = view.startDrag(null,shadowBuilder,view,0);
OnDragListener的代码片段:
private final class ViewDragListener implements OnDragListener { @Override public boolean onDrag(View v,DragEvent event) { int action = event.getAction(); switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: log("ACTION_DRAG_STARTED"); break; case DragEvent.ACTION_DRAG_ENTERED: log("ACTION_DRAG_ENTERED"); break; case DragEvent.ACTION_DRAG_EXITED: log("ACTION_DRAG_EXITED"); case DragEvent.ACTION_DROP: log("ACTION_DROP"); mX = (int) event.getX(); mY = (int)event.getY(); break; case DragEvent.ACTION_DRAG_ENDED: log("ACTION_DRAG_ENDED"); //Doing some cleanup operations. break; case DragEvent.ACTION_DRAG_LOCATION: log("ACTION_DRAG_LOCATION"); break; default: break; } return true; } }