我想爲我的ImageView構建放大和縮小動畫,我設置了一個偵聽器並將動畫RepeatCount設置爲無限。ImageView放大,縮小無限動畫和onAnimation重複問題
首先我開始放大效果,然後在onAnimationRepeat方法中,我使用布爾值創建縮小部分,我想重新開始放大整個效果。但是在第一次onAnimationRepeat沒有被再次調用之後,動畫重複播放,但它仍然卡在縮小部分。
我錯過了什麼?
//image animation
Animation anim = new ScaleAnimation(1.0f, 1.1f, 1.0f, 1.1f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(10000);
zoomIn = true;
// Start animating the image
final ImageView splash = (ImageView) findViewById(R.id.imageView);
splash.startAnimation(anim);
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
if(zoomIn) {
Log.w("", "we zoom out, and zoomIn is: " + zoomIn);
Animation anim = new ScaleAnimation(1.1f, 1f, 1.1f, 1f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(10000);
splash.startAnimation(anim);
zoomIn = false;
} else if(!zoomIn) {
Log.w("", "we zoom in, and zoomIn is: " + zoomIn);
Animation anim = new ScaleAnimation(1.0f, 1.1f, 1.0f, 1.1f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(10000);
splash.startAnimation(anim);
zoomIn = true;
}
}
});
}
應該有'scaleAnim.start()的調用;在'結束。 'setRepeatCount'和'setRepeatMode'是'ObjectAnimator'的方法,而不是'AnimatorSet'。 –