1
我有兩個視圖:一個子視圖和一個父視圖(子視圖是父視圖的一部分);每個視圖都有自己的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);
}
}
}
和你的問題是......? – pskink
當我嘗試滑動孩子時,父母處理該事件。 – user2357536
看到我的答案在這裏:http://stackoverflow.com/questions/16979285/how-to-dispatch-touch-events-to-children-after-consuming – pskink