SimpleOnGestureListener not working for ScrollView

馋奶兔 提交于 2019-12-01 16:40:25
Zaid Daghestani

You have to create a custom ScrollView object and override it's onTouchEvents to also check for your gestures. It's demonstrated in the following code.

public class GestureScrollView extends ScrollView {
    GestureDetector myGesture;

    public GestureScrollView(Context context, GestureDetector gest) {
        super(context);
        myGesture = gest;
    }

    public GestureScrollView(Context context) {
        super(context);
    }

    public GestureScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (myGesture.onTouchEvent(ev))
            return true;
        else
            return super.onTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (myGesture.onTouchEvent(ev))
            return true;
        else
            return super.onInterceptTouchEvent(ev);
        }
    }

Let me know if you run into any issues. :)

-Zaid

I got the solution for this issu

Add following method in the your Activity class

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

As suggested in the below link:

http://groups.google.com/group/android-developers/browse_thread/thread/9fdfb03d0959e299

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!