I am using v4 ViewPager and following the below link able to set the scrolling speed and scrolling animation using interpolator.
Slowing speed of Viewpager controller in android
I had used a linear interpolator when asked in the construtor like this
private void setScroller() {
try {
Field mScroller;
mScroller = ViewPager.class.getDeclaredField("mScroller");
mScroller.setAccessible(true);
FixedSpeedScroller scroller =
new FixedSpeedScroller(this.getContext(), new LinearInterpolator());
mScroller.set(this, scroller);
} catch (NoSuchFieldException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
}
}
Now as i have many pages of views in my viewpages . below to it i had added pagerindicator which consists of dots.
O O O O O O O
Pressing a dot set the current page with smoothScrolling. Using touch events i am able to get the right page number that i need to show. after knowing this i call this method to have a smooth scrolling.
public void snapToPage(int whichPage) {
int numperOfSwapsRequired = whichPage - getCurrentPageIndex();
mScrollingDuration *= numperOfSwapsRequired;
if(numperOfSwapsRequired == 0) return;
if(numperOfSwapsRequired > 0) {
for(int i = 0; i<numperOfSwapsRequired; i++){
setCurrentItem(getCurrentItem()+1, true);
}
} else {
for(int i = 0; i>numperOfSwapsRequired; i--){
setCurrentItem(getCurrentItem()-1, true);
}
}
mScrollingDuration = 300;
}
Now everything works well. But only when i select a dot which is right to the selected page dot. It properly scroll with linear animation.
But when i select dot which is left to the selected page dot. It Don't scroll. It just directly jump to the page with no scrolling animation.
So i am confused how to fix this. Is this related to interpolater or scroller.
Any help would be appreciated.
Thanks