-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c9a876
commit b078e41
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
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
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
57 changes: 57 additions & 0 deletions
57
bannerlibrary/src/main/java/com/github/wanglu1209/bannerlibrary/ViewPagerScroller.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.github.wanglu1209.bannerlibrary; | ||
|
||
import android.content.Context; | ||
import android.support.v4.view.ViewPager; | ||
import android.view.animation.Interpolator; | ||
import android.widget.Scroller; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* Created by WangLu on 2017/3/15. | ||
*/ | ||
|
||
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); | ||
} | ||
|
||
public void initViewPagerScroll(ViewPager viewPager) { | ||
try { | ||
Field mScroller = ViewPager.class.getDeclaredField("mScroller"); | ||
mScroller.setAccessible(true); | ||
mScroller.set(viewPager, this); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* 设置速度速度 | ||
* | ||
* @param duration | ||
*/ | ||
public void setScrollDuration(int duration) { | ||
this.mScrollDuration = duration; | ||
} | ||
} |