我有两个视图:一个子视图和一个父视图(子视图是父视图的一部分);每个 View 都有自己的 onTouchListener。我希望每个视图都处理自己的 onInterceptTouchEvent。马上; 但是,子视图的 onTouchListener 永远不会收到任何事件。它们都被发送到父视图的监听器。如何确保子视图接收到自己的事件?
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
//Log.d(TAG, "onInterceptTouchEvent " + ev);
// handle child events
// note: if you horizontally fling over button its onClick() is not performed
MotionEvent ss = MotionEvent.obtain(ev);
globalVariabels.currentGallery.onTouchEvent(ss);
int bounds[] = {0,0};
globalVariabels.currentGallery.getLocationOnScreen(bounds);
int height = globalVariabels.currentGallery.getHeight() + bounds[0];
int width = globalVariabels.currentGallery.getWidth() + bounds[1];
TouchDelegate delegate = new TouchDelegate(new Rect(0, 0, 2000, 2000), globalVariabels.currentGallery);
setTouchDelegate(delegate);
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
mIgnore = false;
Log.e("ooo", "oo");
Log.e("X:","" + ev.getX());
Log.e("Y:","" + ev.getY());
mNeedToRebase = true;
mInitialX = ev.getX();
mInitialY = ev.getY();
return false ;
}
case MotionEvent.ACTION_MOVE: {
if (!mIgnore) {
Log.e("22", "22");
float deltaX = Math.abs(ev.getX() - mInitialX);
float deltaY = Math.abs(ev.getY() - mInitialY);
mIgnore = deltaX < deltaY;
super.onInterceptTouchEvent(ev);
return !mIgnore;
}
return false;
}
default: {
return super.onInterceptTouchEvent(ev);
}
}
}