代码拳:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
isActionCancel = false;
isTouchOrRunning = true;
lastY = ev.getY();
break;
}
return super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (oa != null && oa.isRunning()) {
ev.setAction(MotionEvent.ACTION_UP);
isActionCancel = true;
}
if (isActionCancel && ev.getAction() != MotionEvent.ACTION_DOWN) {
return false;
}
if (ev.getActionIndex() != 0 && getScrollY() < range) {
ev.setAction(MotionEvent.ACTION_UP);
isActionCancel = true;
}
switch (ev.getAction()) {
case MotionEvent.ACTION_MOVE:
isTouchOrRunning = true;
if (getScrollY() != 0) {
detalY = 0;
lastY = ev.getY();
} else {
detalY = ev.getY() - lastY;
if (detalY > 0) {
setT((int) -detalY / 5);
return true;
}
}
break;
case MotionEvent.ACTION_UP:
isTouchOrRunning = false;
if (getScrollY() < range) {
if (detalY != 0) {
reset();
} else {
toggle();
}
return true;
}
break;
}
return super.onTouchEvent(ev);
}
据我所知,View必须使用ACTION_DOWN事件,以便它可以接收其他的eventaction,但是在上面的代码中,在onTouchEvent()函数中没有处理ACTION_DOWN那里,这个视图怎么能接收ACTION_MOVE和ACTION_UP ??