How to enable Scale in Android ScrollView in a way that doesn't prevent scrolling it and clicking on it's child items?

android, gesturedetector, multi-touch, scrollview

Solution

The solution is to use:

     @Override
    public boolean dispatchTouchEvent(MotionEvent ev){
        super.dispatchTouchEvent(ev);    
        return mScaleDetector.onTouchEvent(ev); 
    }

and not override `onInterceptTouchEvent` and `onTouchEvent` methods.

Problem

I have a custom view that extends Android ScrollView. The direct child is a relative layout which has children that are clickable. I want to be able to: - detect onScale Gesture on the scroll view (than I will manually manage the scale of the items). - scroll the ScrollView vertically. - keep those child items clickable. What I have tried so far is (pseudo code): ``` public class CustomView extends ScrollView { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return super.onInterceptTouchEvent(ev) || mScaleDetector.onTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { return mScaleDetector.onTouchEvent(ev); } private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { @Override public boolean onScale(ScaleGestureDetector detector) { // Handle the scale.. return true; } } } ``` I also tried different configurations for the onInterceptMethod such as first call the super and the return the mScaleDetector.onTouchEvent and so on. I succeeded to intercept the scale or the click and scroll but not both. Thanks, Daniel

Original source