Skip to content

Commit c299a33

Browse files
committed
Fix AnimatorSet duration issue
Setting the duration on an AnimatorSet should propagate that value to its children. This works, but only if all children are added to the set before setDuration() is called. This fix delays that propagation until the set is started, making it possible to have a more flexible order of when the children are added and when the duration is set. Issue #6324904 AnimatorSet durations too long Change-Id: I797971c2310eb2e3fe931b4aa35de505f2a519f7
1 parent 0a1c6c8 commit c299a33

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

core/java/android/animation/AnimatorSet.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,7 @@ public AnimatorSet setDuration(long duration) {
420420
if (duration < 0) {
421421
throw new IllegalArgumentException("duration must be a value of zero or greater");
422422
}
423-
for (Node node : mNodes) {
424-
// TODO: don't set the duration of the timing-only nodes created by AnimatorSet to
425-
// insert "play-after" delays
426-
node.animation.setDuration(duration);
427-
}
423+
// Just record the value for now - it will be used later when the AnimatorSet starts
428424
mDuration = duration;
429425
return this;
430426
}
@@ -456,6 +452,14 @@ public void start() {
456452
mTerminated = false;
457453
mStarted = true;
458454

455+
if (mDuration >= 0) {
456+
// If the duration was set on this AnimatorSet, pass it along to all child animations
457+
for (Node node : mNodes) {
458+
// TODO: don't set the duration of the timing-only nodes created by AnimatorSet to
459+
// insert "play-after" delays
460+
node.animation.setDuration(mDuration);
461+
}
462+
}
459463
// First, sort the nodes (if necessary). This will ensure that sortedNodes
460464
// contains the animation nodes in the correct order.
461465
sortNodes();

0 commit comments

Comments
 (0)