I've got a Horizontal Scroll View placed in ViewPager. The goal is to use only software triggered scrolling of Horizontal Scroll View. All the scrolling gestures should be handled by the view pager.
I already did it by creating a custom View Pager that intercepts all swipe gestures:
public class GreedyViewPager extends ViewPager {
GestureDetector mGestureDetector;
View.OnTouchListener mGestureListener;
public GreedyViewPager(Context context) {
super(context);
initGestureDetector(context);
}
public GreedyViewPager(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
initGestureDetector(context);
}
void initGestureDetector(Context context){
mGestureDetector = new GestureDetector(context, new ScrollDetector());
ViewConfiguration vc = ViewConfiguration.get(context);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return super.onInterceptTouchEvent(ev) || mGestureDetector.onTouchEvent(ev);
}
class ScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
return true;
}
}
}
Unfortunately it doesn't work well with all devices, sometimes I have to swipe a coupe of times in order to go to the next position in the ViewPager.
Any idea how to make it better?