Skip to content

Instantly share code, notes, and snippets.

@PPartisan
Last active March 16, 2016 13:04
Show Gist options
  • Save PPartisan/e8494c20464164d0bbf8 to your computer and use it in GitHub Desktop.
Save PPartisan/e8494c20464164d0bbf8 to your computer and use it in GitHub Desktop.
Slightly altered ViewPager that has a more natural speed when executing a programmatic swipe between pages
public class SlowAutoSwipeViewPager extends ViewPager {
public SlowAutoSwipeViewPager(Context context) {
super(context);
}
public SlowAutoSwipeViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setCurrentItem(int item, boolean smoothScroll) {
try {
Method method = ViewPager.class.getDeclaredMethod(
"setCurrentItemInternal", int.class, boolean.class, boolean.class, int.class
);
method.setAccessible(true);
method.invoke(this, item, true, false, 200);
} catch (Exception e) {
e.printStackTrace();
super.setCurrentItem(item, smoothScroll);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment