在CollapsingToolbarLayout中自定义手势检测

时间:2015-11-18 00:27:54

标签: java android view gesture android-collapsingtoolbarlayout

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

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

1 个答案:

答案 0 :(得分:0)

经过一些调查,我发现问题出在onTouchEvent上,具体来说,你需要为父视图请求DisceptInterceptTouchEvent,以便parafront视图不处理触摸事件:

    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;
}