Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改滚动触发和暂停位置, 只有当view要现实在窗口时才滚动,当view从窗口渲染中取消时暂停滚动 #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class AutoScrollViewPager extends ViewPager {
/** scroll factor for swipe scroll animation, default is 1.0 **/
private double swipeScrollFactor = 1.0;

/** first scroll delay time */
private long delayTimeInMills;

private Handler handler;
private boolean isAutoScroll = false;
private boolean isStopByTouch = false;
Expand Down Expand Up @@ -91,7 +94,7 @@ private void init() {
*/
public void startAutoScroll() {
isAutoScroll = true;
sendScrollMessage((long)(interval + scroller.getDuration() / autoScrollFactor * swipeScrollFactor));
this.delayTimeInMills = (long)(interval + scroller.getDuration() / autoScrollFactor * swipeScrollFactor);
}

/**
Expand All @@ -101,15 +104,40 @@ public void startAutoScroll() {
*/
public void startAutoScroll(int delayTimeInMills) {
isAutoScroll = true;
sendScrollMessage(delayTimeInMills);
this.delayTimeInMills = delayTimeInMills;
}

/**
* start scroll when view attached
*/
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if(isAutoScroll){
sendScrollMessage(delayTimeInMills);
}
}

/**
* stop scroll when view detached
*/
@Override
protected void onDetachedFromWindow() {
if(isAutoScroll){
handler.removeMessages(SCROLL_WHAT);
}
super.onDetachedFromWindow();
}


/**
* stop auto scroll
*/
public void stopAutoScroll() {
isAutoScroll = false;
handler.removeMessages(SCROLL_WHAT);
if(isAutoScroll){
isAutoScroll = false;
handler.removeMessages(SCROLL_WHAT);
}
}

/**
Expand Down