Android动画不重复

时间:2017-01-26 08:31:06

标签: android animation

我有一个非常简单的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();

} 

问题是动画没有重复,我试过这个:

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

并且动画只重复两次然后停止

2 个答案:

答案 0 :(得分:0)

在xml中设置repeatCount和repeatMode,并从代码中删除

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

Android Studio没有为您提供有关此属性的建议,您应该手动编写。

答案 1 :(得分:0)

此代码适合我

        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);