【发布时间】:2015-04-06 12:23:37
【问题描述】:
我在父布局上放置视图。我想通过长按 L1 来拖动整个视图。当我长按 L1 时,视图进入拖动模式,但将触摸位置更改为视图中心 (x,y)。 我想按住布局(L1)的上栏拖动视图。
View:
______________
|______L1______|
| |
y | L2 |
| |
|______________|
x
@Override
public boolean onDrag(View v, DragEvent event) {
// Handles each of the expected events
switch (event.getAction()) {
//signal for the start of a drag and drop operation.
case DragEvent.ACTION_DRAG_STARTED:
// do nothing
break;
//the drag point has entered the bounding box of the View
case DragEvent.ACTION_DRAG_ENTERED:
v.setBackground(targetShape); //change the shape of the view
break;
//the user has moved the drag shadow outside the bounding box of the View
case DragEvent.ACTION_DRAG_EXITED:
v.setBackground(normalShape); //change the shape of the view back to normal
break;
//drag shadow has been released,the drag point is within the bounding box of the View
case DragEvent.ACTION_DROP:
doStuff();
break;
//the drag and drop operation has concluded.
case DragEvent.ACTION_DRAG_ENDED:
v.setBackground(normalShape); //go back to normal shape
default:
break;
}
return true;
}
【问题讨论】:
标签: android view drag-and-drop position touch