maysara
maysara

Reputation: 6429

Android Animation doesn't repeat

I have this very simple Animation for ImageView

<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
    android:duration="1300"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"/>

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splashscreen);
    ImageView imageView = (ImageView)findViewById(R.id.splash_logo);
    final Animation animation = AnimationUtils.loadAnimation(this,R.anim.rotate);
    animation.setRepeatMode(Animation.INFINITE);
    animation.setRepeatCount(Animation.INFINITE);
    imageView.setAnimation(animation);
    animation.start();

} 

the problem is that the animation does not repeat, I tried this:

@Override
public void onAnimationEnd(Animation animation) {
    animation.start();
}

and the animation just repeats for two times then stops

Upvotes: 0

Views: 2489

Answers (2)

maysara
maysara

Reputation: 6429

this code works for me

        RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF,
            0.5f,  Animation.RELATIVE_TO_SELF, 0.5f);
    rotate.setRepeatCount(Animation.INFINITE);
    rotate.setRepeatMode(Animation.INFINITE);
    rotate.setDuration(500);
    imageView.startAnimation(rotate);

Upvotes: 0

Levon Vardanyan
Levon Vardanyan

Reputation: 420

Set repeatCount and repeatMode in xml, and remove from code

android:repeatMode="restart"
android:repeatCount="infinite"

Android studio doesn't give you suggestions for this attributes, you should write manually.

Upvotes: 2

Related Questions