Java MotionEvent未启动
我想实现一个拖放,但结果是非常耗时,下面是有问题的代码:Java MotionEvent未启动,java,android,ontouchlistener,Java,Android,Ontouchlistener,我想实现一个拖放,但结果是非常耗时,下面是有问题的代码: public class MyTouchListener implements View.OnTouchListener { public static float sharedX,sharedY; public boolean onTouch(View view, MotionEvent motionEvent) { sharedX = motionEvent.getX(); sharedY = motionEv
public class MyTouchListener implements View.OnTouchListener {
public static float sharedX,sharedY;
public boolean onTouch(View view, MotionEvent motionEvent) {
sharedX = motionEvent.getX();
sharedY = motionEvent.getY();
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(data, shadowBuilder, view, 0);
view.setVisibility(View.INVISIBLE);
return true;
case MotionEvent.ACTION_CANCEL:
break;
case MotionEvent.ACTION_MOVE:
view.setVisibility(View.VISIBLE);
break;
case MotionEvent.ACTION_UP:
view.setVisibility(View.VISIBLE);
break;
}
return false;
}
}
虽然action cancel没有给出正确的结果(motionevent.getX不是一个正常的正常值),但action down和action cancel正在被触发
其他事件都没有发生。我不明白为什么,我放弃了尝试