CollapsingToolbarLayout 内的自定义手势检测

Custom gesture detection inside CollapsingToolbarLayout

我正在尝试使用我在 CollapsingToolbarLayout 中编写的自定义视图,但触摸事件似乎没有正确传播到带有手势检测的自定义视图。结果是滚动和与视图的交互没有按预期或顺利地工作。我的自定义视图大量使用 GestureDetector.SimpleOnGestureListener

是否可以在 CollapsingToolbarLayout 中嵌入具有自己的触摸事件的自定义视图?

经过一番排查,发现是onTouchEvent的问题,具体需要父view请求DisallowInterceptTouchEvent,让父view不处理touch事件:

    public boolean onTouchEvent(MotionEvent event) {
      // Do stuff on touch 
      // prevent parent container from processing ACTION_MOVE events
      if(event.getAction() == MotionEvent.ACTION_MOVE) {
        getParent().requestDisallowInterceptTouchEvent(true);
      } else if(event.getAction() == MotionEvent.ACTION_CANCEL) {
        getParent().requestDisallowInterceptTouchEvent(false);
      }

    // Do some more stuff
    return true;
}