Reputation: 17105
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)?
Upvotes: 8
Views: 16158
Reputation: 3448
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();
Upvotes: 7
Reputation: 17105
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>
Upvotes: 5
Reputation: 39836
just ask it to repeat:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially"
android:repeatMode="reverse"
android:repeatCount="infinite">
=)
count can also be a defined number.
Upvotes: -2
Reputation: 11541
You need to set a repeat mode to the AnimationSet, see:
http://developer.android.com/reference/android/view/animation/Animation.html#attr_android:repeatMode
Upvotes: -1