Skip to content

Instantly share code, notes, and snippets.

@ponnamkarthik
Created September 15, 2017 12:59
Show Gist options
  • Save ponnamkarthik/6b2e358ffd66ec84673ce472e177fdcc to your computer and use it in GitHub Desktop.
Save ponnamkarthik/6b2e358ffd66ec84673ce472e177fdcc to your computer and use it in GitHub Desktop.
ViewPage Scrolling Duration
try {
Field mScroller = null;
mScroller = ViewPager.class.getDeclaredField("mScroller");
mScroller.setAccessible(true);
ViewPagerScroller scroller = new ViewPagerScroller(viewPager.getContext());
mScroller.set(viewPager, scroller);
} catch (Exception e) {
Log.e("GHM", "error ", e);
}
package com.rcc.newdesign.utils;
import android.content.Context;
import android.view.animation.Interpolator;
import android.widget.Scroller;
/**
* Created by ponna on 15-09-2017.
*/
public class ViewPagerScroller extends Scroller {
private int mScrollDuration = 1000;
public ViewPagerScroller(Context context) {
super(context);
}
public ViewPagerScroller(Context context, Interpolator interpolator) {
super(context, interpolator);
}
public ViewPagerScroller(Context context, Interpolator interpolator, boolean flywheel) {
super(context, interpolator, flywheel);
}
@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
super.startScroll(startX, startY, dx, dy, mScrollDuration);
}
@Override
public void startScroll(int startX, int startY, int dx, int dy) {
super.startScroll(startX, startY, dx, dy, mScrollDuration);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment