Skip to content

Commit eb9984b

Browse files
committed
Avoid views flickering when interrupting a scroll
If you start a new scroll while the scroll animation is in progress, onInterceptTouchEvent will call mScroller.abortAnimation, and when computeScroll is next called, postViewSwitched will run. As computeScroll is called within View.draw, this is not a good time to be fiddling with the layout by adding and removing children. It causes the wrong view to be drawn for a frame when this happens. Instead of calling postViewSwitched immediately, I've changed it to be posted to the handler so it will be called after this frame has finished drawing and before the next is laid out.
1 parent 97740a6 commit eb9984b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

viewflow/src/org/taptwo/android/widget/ViewFlow.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,11 @@ public void computeScroll() {
499499
mCurrentScreen = Math.max(0,
500500
Math.min(mNextScreen, getChildCount() - 1));
501501
mNextScreen = INVALID_SCREEN;
502-
postViewSwitched(mLastScrollDirection);
502+
post(new Runnable() {
503+
@Override public void run() {
504+
postViewSwitched(mLastScrollDirection);
505+
}
506+
});
503507
}
504508
}
505509

0 commit comments

Comments
 (0)