重写了onTouchEvent方法,结果怎么着,没有收到ACTION_DOWN事件
普通的点击长按DOWN和UP都收不到。滑动一段距离不收到DOWN而直接收到MOVE事件,收到MOVE事件后抬起手指时可以收到UP事件
@Override
public boolean onTouch(View v, MotionEvent event) {
System.out.println(event.getAction());
int action = event.getAction();
if(action==MotionEvent.ACTION_UP){
System.out.println(reference);
if(reference!=null){
reference.setAlpha(1f);
reference=null;
}
}else if(action==MotionEvent.ACTION_DOWN){
posX0=event.getX();
posY0=event.getY();
}else if(action==MotionEvent.ACTION_MOVE){
cX=event.getX();
cY=event.getY();
System.out.println(cX+" "+cY);
}
return true;
}
得到的输出里短距离滑动或者点按长按时没有,长距离滑动时22222(ACTION_MOVE)1(ACTION_UP)
试试
public boolean dispatchKeyEvent(KeyEvent event) {
return super.dispatchKeyEvent(event);
}