adjust frame distance to make scrolling smoother.
Root Cause: At the end of a scroll gesture, as the velocity drops, the per-frame distance approximation oscillates between 1 px and 0 px, resulting in visible jitter. Solution: During the scroll, if the computed distance for the next frame is 0 px, force it to 1 px to keep the animation continuous to eliminate jitter. Bug: 425738878 Test:scroll on the activity of app using ListView, observe whether exist jitter. Change-Id: I1dae1283f9cd084db841c5f807376268eedc75b5 Signed-off-by: Pranav Vashi <neobuddy89@gmail.com> Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
@@ -670,6 +670,9 @@ public class OverScroller {
|
||||
// Current position
|
||||
private int mCurrentPosition;
|
||||
|
||||
// last frame position
|
||||
private int mLastPosition;
|
||||
|
||||
// Final position
|
||||
private int mFinal;
|
||||
|
||||
@@ -1319,6 +1322,17 @@ public class OverScroller {
|
||||
|
||||
mCurrentPosition = mStart + (int) Math.round(distance);
|
||||
|
||||
int deltaDistance = mCurrentPosition - mLastPosition;
|
||||
if (!mFinished && deltaDistance == 0) {
|
||||
int direction = mFinal > mStart ? 1 : -1;
|
||||
mCurrentPosition += direction;
|
||||
if ((direction > 0 && mCurrentPosition > mFinal) ||
|
||||
(direction < 0 && mCurrentPosition < mFinal)) {
|
||||
mCurrentPosition = mFinal;
|
||||
}
|
||||
}
|
||||
mLastPosition = mCurrentPosition;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user