OSDN Git Service

Add safety net if StackView duration would be negative.
authorTony Wickham <twickham@google.com>
Mon, 7 Nov 2016 18:18:55 +0000 (10:18 -0800)
committerTony Wickham <twickham@google.com>
Mon, 7 Nov 2016 18:27:41 +0000 (18:27 +0000)
Bug: 32699754
Change-Id: I00d4b2398fa7f4ab4cdad290a346b0f09c2af242

core/java/android/widget/StackView.java

index 0e99c02..1b9055c 100644 (file)
@@ -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;