3
ondrag當類別:拖放到目標後放回到原來的位置與Android的陰影?
private class ChoiceDragListener implements OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// no action necessary
break;
case DragEvent.ACTION_DRAG_ENTERED:
// no action necessary
break;
case DragEvent.ACTION_DRAG_EXITED:
// no action necessary
break;
case DragEvent.ACTION_DROP:
// handle the dragged view being dropped over a drop view
View view = (View) event.getLocalState();
dropTarget = (RelativeLayout) v;
dropped = (RelativeLayout) view;
tagDropped = dropped.getTag().toString();
Log.i("tagDropped", "" + tagDropped);
tagDropTarget = dropTarget.getTag().toString();
Log.i("tagDropTarget", "" + tagDropTarget);
matchTag();
break;
case DragEvent.ACTION_DRAG_ENDED:
// no action necessary
break;
default:
break;
}
return true;
}
}
ChoiceTouchListener類:
private final class ChoiceTouchListener implements OnTouchListener {
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
/*
* Drag details: we only need default behavior - clip data could
* be set to pass data as part of drag - shadow can be tailored
*/
ClipData data = ClipData.newPlainText("", "");
DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
view);
// start dragging the item touched
view.startDrag(data, shadowBuilder, view, 0);
return true;
} else {
return false;
}
}
}
現在我想在原來的位置移動對象,其中就拖
我尋找這樣的,但沒有回答任何一個drag and drop with onDraglistener animate to go back to original position if not dropped on target