From 103dd8fee1a6eb7698429c4b6d2b1c1fabb0b4b3 Mon Sep 17 00:00:00 2001 From: MOVZX Date: Fri, 2 Jan 2026 22:26:20 +0700 Subject: [PATCH] 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 Signed-off-by: MOVZX --- core/java/android/widget/OverScroller.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/java/android/widget/OverScroller.java b/core/java/android/widget/OverScroller.java index 614cd1739e364..d1fbe2f8097aa 100644 --- a/core/java/android/widget/OverScroller.java +++ b/core/java/android/widget/OverScroller.java @@ -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; } }