I used this answer from a stackoveflow question about enabling a custom Scroller for ViewPager's slide animation and it works smoothly. It extends Scroller's class and uses reflection to access the mScroller
field.
What I want now is when some conditions have been met ( onTouch() and a timer ) to revert back to the default scroll animation.
Tried to clone the mScroller
field :
Interpolator decelerator = new DecelerateInterpolator();
try {
mScroller = ViewPager.class.getDeclaredField("mScroller");
cloneDefaultScroller = mScroller;
mScroller.setAccessible(true);
scroller = new CarouselScroller(pager.getContext(), decelerator);
mScroller.set(pager, scroller);
} catch (NoSuchFieldException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
}
enable it again like this
cloneDefaultScroller.setAccessible(true);
Scroller scroller1 = new Scroller(this);
cloneDefaultScroller.set(pager, scroller1)
where cloneDefaultScroller
and mScroller
are :
Field mScroller;
Field cloneDefaultScroller;
but what I get is a scroller that only moves a few pixels and I have to try like 10 times to have a "normal" scroll ( from one page to another ).
Anyone can help with that? Thank you