我拼命想解决这个问题: 只有ACTION_DOWN事件才会触发我的方法。整整一天,它工作得很好,但现在它不再起作用,但我没有改变任何东西。
public boolean onTouch(View v, MotionEvent event) {
boolean isReleased = event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL;
boolean isPressed = event.getAction() == MotionEvent.ACTION_DOWN;
boolean isMoved = event.getAction() == MotionEvent.ACTION_MOVE;
if(isPressed){
if(Gesture_Done){
reset_It();
}
xPressed = event.getX();
yPressed = event.getY();
action_timelist.add(System.currentTimeMillis());
if(action_timelist.size()>1){
evaluate_actionlist(true);
}
}
else if(isReleased){
if(!Gesture_Done){
action_timelist.add(System.currentTimeMillis());
evaluate_actionlist(false);
}
Gesture_Done=false;
}
else if(isMoved){
xMoved = xPressed - event.getX();
yMoved = yPressed - event.getY();
checkGesture();
}
return false;
}
因为没有显示错误,我不知道如何解决它..
答案 0 :(得分:3)
尝试使用下面编辑的代码。几个小时前我遇到了完全相同的问题,这是因为即使我正在消耗触摸事件,我也返回了假设。如果您对事件采取行动,则以下代码返回true,否则返回false。
public boolean onTouch(View v, MotionEvent event) {
boolean isReleased = event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL;
boolean isPressed = event.getAction() == MotionEvent.ACTION_DOWN;
boolean isMoved = event.getAction() == MotionEvent.ACTION_MOVE;
if(isPressed){
if(Gesture_Done){
reset_It();
}
xPressed = event.getX();
yPressed = event.getY();
action_timelist.add(System.currentTimeMillis());
if(action_timelist.size()>1){
evaluate_actionlist(true);
}
return true;
}
else if(isReleased){
if(!Gesture_Done){
action_timelist.add(System.currentTimeMillis());
evaluate_actionlist(false);
}
Gesture_Done=false;
return true;
}
else if(isMoved){
xMoved = xPressed - event.getX();
yMoved = yPressed - event.getY();
checkGesture();
return true;
}
return false;
}