I have made an AnimatorSet of three ObjectAnimator which I want to repeat sequentally.
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially">
<objectAnimator
android:propertyName="rotation"
android:duration="300"
android:valueFrom="0"
android:valueTo="5"
android:valueType="floatType"/>
<objectAnimator
android:propertyName="rotation"
android:duration="600"
android:valueFrom="5"
android:valueTo="-5"
android:valueType="floatType"/>
<objectAnimator
android:propertyName="rotation"
android:duration="300"
android:valueFrom="-5"
android:valueTo="0"
android:valueType="floatType"/>
</set>
But if I set the CycleInterpolator to AnimatorSet because the Animators will start sequentally
public void setInterpolator (TimeInterpolator interpolator) Added in API level 11
Sets the TimeInterpolator for all current child animations of this AnimatorSet.
So I tried looping by restarting AnimatorSet by setting a listener, but it stops for few milliseconds and the effect of restarting AnimatorSet is noticeable.
a.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation)
{
animation.start();
}
});
What can I do to loop it (except building a huge list of ObjectAnimators or writing my own animation using Thread and Handler)?
In desperate need of this feature too, turns out some one already have found the solution.
http://www.jefflinwood.com/2013/04/repeating-android-animations-with-animatorset/
All credit belongs to the original author.
mAnimationSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
mAnimationSet.start();
}
});
mAnimationSet.start();
A workaround for this particular case is creating an AnimatorSet with first item to rotate one half and the second to keep rotating
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially">
<objectAnimator
android:propertyName="rotation"
android:duration="150"
android:valueFrom="0"
android:valueTo="-5"
android:valueType="floatType"/>
<objectAnimator
android:propertyName="rotation"
android:duration="300"
android:valueFrom="-5"
android:valueTo="5"
android:repeatMode="reverse"
android:repeatCount="infinite"
android:valueType="floatType"/>
</set>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With