Last active
March 16, 2016 13:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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