我正在尝试在recyclerview的内部放置滚动mapView,因此,我在触摸时和之后设置了requestDisallowInterceptTouchEvent()
。
奇怪的是:如果我在dispatchTouchEvent()
方法中设置它,这确实可以工作,但是如果我在onTouchEvent()
方法中进行相同操作,则它不起作用。
有人可以解释为什么我不能在 onTouchEvent()
中设置它?
工作:
public class WorkingScrollableListItemMapView extends MapView {
// constructors
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// Stop parents from handling the touch
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow parents from handling the touch
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return super.dispatchTouchEvent(ev);
}
}
不工作:
public class NotWorkingScrollableListItemMapView extends MapView {
// constructors
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_UP:
// Allow parents from handling the touch
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
case MotionEvent.ACTION_DOWN:
// Stop parents from handling the touch
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return super.onTouchEvent(ev);
}
}
处理事件的调用序列有些以下顺序:OnInterceptTouchevent,OnDisPatchTouchEvent,DispatchTouchEvent,Ontouchevent。对我来说,这表明OnTouchEvent是处理事件的最后一步。为时已晚操作在哪里&谁在最后一步中处理活动。如果您查看处理事件的早期方法,源代码怎么说?