I am trying to make an animation in my Activity, to be repeated infinite times. I have already tried it in XML file with repeatCount and repeatMode attributes, but it doesn't work. The thing is that myanimation.xml file is constructed of a set of different animations.
My XML file for that animation
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/bounce_interpolator"
>
<translate
android:startOffset="1000"
android:fillAfter="true"
android:fromXDelta="10"
android:fromYDelta="10"
android:toXDelta="50"
android:toYDelta="-200"
android:duration="1800"
android:interpolator="@android:anim/bounce_interpolator"
/>
<translate
android:fillAfter="true"
android:startOffset="2000"
android:fromYDelta="10"
android:fromXDelta="10"
android:toXDelta="100"
android:toYDelta="270"
android:duration="1800"
android:interpolator="@android:anim/bounce_interpolator" />
<translate
android:fillAfter="true"
android:startOffset="3000"
android:fromYDelta="10"
android:fromXDelta="10"
android:toXDelta="130"
android:toYDelta="-270"
android:duration="1800"
android:interpolator="@android:anim/bounce_interpolator"
/>
<translate
android:fillAfter="true"
android:startOffset="4000"
android:fromYDelta="10"
android:fromXDelta="10"
android:toXDelta="140"
android:toYDelta="270"
android:duration="1800"
android:interpolator="@android:anim/bounce_interpolator"
/>
<translate
android:fillAfter="true"
android:startOffset="5000"
android:fromYDelta="10"
android:fromXDelta="10"
android:toXDelta="90"
android:toYDelta="-270"
android:duration="1800"
android:interpolator="@android:anim/bounce_interpolator"
/>
And in onCreate() I have animation tied to a ImageView object.
ImageView ball = (ImageView) findViewById(R.id.animationBall);
final Animation myAnimation = AnimationUtils.loadAnimation(this, R.anim.ball_animation);
ball.startAnimation(myAnimation);
The animation works fine, the only thing is that it doesn't want to repeat itself, even if I set the setRepeatMode() or setRepeatCount() methods.
For what its worth,
setRepeatMode()andsetRepeatCount()have to be set on theAnimationobjects, and not on theAnimationSetobject. That's potentially a mistake you may have made.So either call those methods on the
Animationobjects or add those attributes to the XML of thetranslateschema.Another approach is to set an endlessly repeating animation as follows: