Sun Sun - 1 year ago 155
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
Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download