Skip to content Skip to sidebar Skip to footer

Viewpager Swipe With 2 Fingers

I would to implement a ViewPager swipe with two fingers. I tried to implement a sublcass of ViewPager overriding the onTouchEvent and passing the method to superclass only if the t

Solution 1:

Overriding onInterceptTouchEvent() should do the trick. According to the comments in the ViewPager sources, it's there where the decision is made whether scrolling should start or not.

Solution 2:

im writing this code and its working for two finger .

booleanfreeTwo=false;

@OverridepublicbooleanonTouchEvent(MotionEvent ev) {

    finalintaction= ev.getAction() & MotionEventCompat.ACTION_MASK;
    intcounter= ev.getPointerCount() ;

    if(counter == 1 && (action== MotionEvent.ACTION_DOWN || action== MotionEvent.ACTION_MOVE) && !freeTwo)
    {
        if(action == MotionEvent.ACTION_MOVE)
            freeTwo = true;
        returnsuper.onTouchEvent(ev);
    }

    if(counter == 2 && (action== MotionEvent.ACTION_POINTER_DOWN|| action== MotionEvent.ACTION_MOVE || action== MotionEvent.ACTION_POINTER_UP) && freeTwo)
    {
        if(action== MotionEvent.ACTION_POINTER_UP)
            freeTwo = false;
        returnsuper.onTouchEvent(ev);
    }

    ev.setAction(MotionEvent.ACTION_UP);
    returnsuper.onTouchEvent(ev);
}

Post a Comment for "Viewpager Swipe With 2 Fingers"