opt
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package com.mogo.commons.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.Scroller;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/19
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
class ViewPagerSpeedScroller extends Scroller {
|
||||
|
||||
private int mFixedDuration = 1500;
|
||||
|
||||
public ViewPagerSpeedScroller( Context context ) {
|
||||
super( context );
|
||||
}
|
||||
|
||||
public ViewPagerSpeedScroller( Context context, Interpolator interpolator ) {
|
||||
super( context, interpolator );
|
||||
}
|
||||
|
||||
public ViewPagerSpeedScroller( Context context, Interpolator interpolator, boolean flywheel ) {
|
||||
super( context, interpolator, flywheel );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startScroll( int startX, int startY, int dx, int dy ) {
|
||||
startScroll( startX, startY, dx, dy, mFixedDuration );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startScroll( int startX, int startY, int dx, int dy, int duration ) {
|
||||
super.startScroll( startX, startY, dx, dy, mFixedDuration );
|
||||
}
|
||||
|
||||
public void setFixedDuration( int duration ) {
|
||||
this.mFixedDuration = duration;
|
||||
}
|
||||
|
||||
public static void attach( Context context, Object pager, int duration ) {
|
||||
try {
|
||||
Field filed = pager.getClass().getDeclaredField( "mScroller" );
|
||||
filed.setAccessible( true );
|
||||
ViewPagerSpeedScroller scroller = new ViewPagerSpeedScroller( context, new DecelerateInterpolator() );
|
||||
scroller.setFixedDuration( duration );
|
||||
filed.set( pager, scroller );
|
||||
|
||||
Field field = pager.getClass().getDeclaredField( "mTouchSlop" );
|
||||
field.setAccessible( true );
|
||||
field.setInt( pager, 4 );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user