Sun Sun - 8 months ago 78
Android Question

Custom gesture detection inside CollapsingToolbarLayout

I'm trying to use a custom view that I've written inside a CollapsingToolbarLayout, but it seems that the touch events are not propagating properly to my custom view with gesture detection. The result is that scrolling and interactions with the view are not working as expected or smoothly. My custom view makes heavy use of


Is it possible to embed a custom view which has it's own touch events inside CollapsingToolbarLayout?

Sun Sun

After some investigation, I found that the problem was with onTouchEvent, specifically, you need to requestDisallowInterceptTouchEvent for the parent view so that the paraent view does not process the touch event:

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

    // Do some more stuff
    return true;