0
在子對象中,我們需要跟蹤座標(ACTION_MOVE)。如果座標爲getX() > x
,我們必須將事件發送給父對象。Android:處理觸摸事件在父子發送(OnTouchListener)
問題:要將事件發送給父級,我們需要返回false,但是如果返回false,我們將無法跟蹤子級中對象的座標。
public boolean onTouch(View v,MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_MOVE) {
if (e.getY() > 200) {
return false; //we must send event to the parent object, but since then the ACTION_MOVE event no longer occurs here
} else {
myView.setTranslationY(e.getY());
return true; //we have to handle the event here
}
}
return false;
}
如何正確處理這兩種情況?