diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java index 0e99c02cc6aa3..1b9055ce33abd 100644 --- a/core/java/android/widget/StackView.java +++ b/core/java/android/widget/StackView.java @@ -1051,6 +1051,11 @@ public class StackView extends AdapterViewAnimator { float d = (float) Math.hypot(viewLp.horizontalOffset, viewLp.verticalOffset); float maxd = (float) Math.hypot(mSlideAmount, 0.4f * mSlideAmount); + if (d > maxd) { + // Because mSlideAmount is updated in onLayout(), it is possible that d > maxd + // if we get onLayout() right before this method is called. + d = maxd; + } if (velocity == 0) { return (invert ? (1 - d / maxd) : d / maxd) * DEFAULT_ANIMATION_DURATION;