wkh*_*tch 4 android objectanimator
我有以下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;
}
Run Code Online (Sandbox Code Playgroud)
这是在var上设置的,称为throbber,偶尔会通过以下方法更新:
private void updateThrobbing() {
if (hasThrob()) {
throbber = dialCenterThrob();
throbber.start();
} else {
if (throbber != null && throbber.isRunning()) {
stopThrobbing();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我不能让它停止动画,这是目前尝试这样做的方法:
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();
}
Run Code Online (Sandbox Code Playgroud)
我不能让它停止动画.更新:我只是尝试将本地ref存储到单个对象动画师,然后调用setRepeatCount,mode,pause,end,取消每个,但仍然没有.
Ani*_*kur 24
dialCenterImageView.clearAnimation();
这对创建的动画没有影响ObjectAnimator.您只能清除已在视图上启动的动画startAnimation()
findViewById(R.id.yourViewId).startAnimation(yourAnimation);
findViewById(R.id.yourViewId).clearAnimation();
Run Code Online (Sandbox Code Playgroud)
任何对象动画师,或者设置为无限的repeatCount的动画师都不会停止,无论你做什么,都不会离开视图.
诚然!今天学到了这个艰难的道路.所以会增加我的两分钱.您需要存储ObjectAnimator实例的引用,然后再调用cancel()它.
旋转Android手机屏幕后动画仍在继续时我遇到了这种情况,在这种情况下,您的活动基本上是用新布局重新创建的.
所以这就是我所做的
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
ObjectAnimator buttonOneObjectAnimator = myOnClickListener.getButtonOneColorAnim();
if(buttonOneObjectAnimator != null)
buttonOneObjectAnimator.cancel();
}
Run Code Online (Sandbox Code Playgroud)
你也可以很好地做到这onPause()一点.
另一个需要注意的重点.如果你打电话给start()你的ObjectAnimator情况n次,那么你将不得不调用cancel() n次的动画完全停止.
此外,如果您AnimatorSet添加了侦听器,请确保在调用cancel之前删除了侦听器.
yourAnimatorSet.removeAllListeners();
yourAnimatorSet.end();
yourAnimatorSet.cancel();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7641 次 |
| 最近记录: |