我正在尝试在我的应用上记录每个触摸事件。 到目前为止,我可以记录每个移动和触摸事件,但是当使用拖放时,拖动阴影会覆盖常规移动事件。 我想知道的是,是否有办法获得拖影的每个运动的x和y坐标。
答案 0 :(得分:3)
@Override
public boolean onDrag(View v, DragEvent event) {
int action = event.getAction();
ViewGroup owner = (ViewGroup) v.getParent();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
break;
case DragEvent.ACTION_DRAG_LOCATION:
mCurX = (int) event.getX();
mCurY = (int) event.getY();
mText.setText("Cur(X, Y) : " + mCurX + ", " + mCurY );
break;
case DragEvent.ACTION_DRAG_ENTERED:
dragState = "DRAG_ENTERED";
break;
case DragEvent.ACTION_DRAG_EXITED:
dragState = "DRAG_EXITED";
break;
case DragEvent.ACTION_DROP:
Log.d(TAG, "ACTION_DRAG_ENDED");
break;
case DragEvent.ACTION_DRAG_ENDED:
if(dragState == "DRAG_EXITED"){
DropAction();
}
break;
default:
break;
}
return true;