我有以下的AnimatorSet方法:
private AnimatorSet dialCenterThrob() {
int bpm = workoutStream.getHeartRate();
dialCenterImageView.clearAnimation();
AnimatorSet finalSet = new AnimatorSet();
ObjectAnimator pulseX = ObjectAnimator.ofFloat(dialCenterImageView, View.SCALE_X, 0.98f, 1.06f);
ObjectAnimator pulseY = ObjectAnimator.ofFloat(dialCenterImageView, View.SCALE_Y, 0.98f, 1.06f);
pulseX.setRepeatMode(ObjectAnimator.REVERSE);
pulseX.setRepeatCount(ObjectAnimator.INFINITE);
pulseY.setRepeatMode(ObjectAnimator.REVERSE);
pulseY.setRepeatCount(ObjectAnimator.INFINITE);
pulseX.setDuration(bpm);
pulseY.setDuration(bpm);
pulseX.setInterpolator(new AccelerateInterpolator());
pulseY.setInterpolator(new AccelerateInterpolator());
finalSet.playTogether(pulseX, pulseY);
return finalSet;
}
这个变量名为throbber,它会被设置,并且偶尔会被这个方法更新:
private void updateThrobbing() {
if (hasThrob()) {
throbber = dialCenterThrob();
throbber.start();
} else {
if (throbber != null && throbber.isRunning()) {
stopThrobbing();
}
}
}
但我无法停止它的动画,以下是当前尝试停止动画的方法:
public void stopThrobbing() {
List<Animator> throbbers = throbber.getChildAnimations();
for(Animator animator : throbbers) {
//accomplishes nothing
((ObjectAnimator)animator).setRepeatCount(0);
((ObjectAnimator)animator).setRepeatMode(0);
}
throbber.pause(); //nothing
throbber.cancel(); //and again, nothing
throbber.end();//shocking, I know, but really, nothing
throbber = null;//you'd think this would definitely do it, but no
//desparate attempt, in vein, of course
dialCenterImageView.clearAnimation();
}
我无法停止它的动画。更新:我刚刚尝试了将各个对象动画器的本地引用存储起来,然后在每个动画器上调用setRepeatCount、mode、pause、end、cancel,但仍然没有效果。
clearAnimation
方法将完全没有任何效果。该方法清除了视图的Animation
,这是一个与对象Animator
完全不同的概念。 - Alex LockwoodpulseX.setRepeatMode(ObjectAnimator.);
。你能修复一下吗? - Alex Lockwood