我有一个 AnimationDrawable,它播放帧动画,然后下一个 Activity 以圆形显示动画开始:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
AnimationDrawable animationDrawable =
(AnimationDrawable) mAnimationSceneImage.getDrawable();
animationDrawable.start();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
startMapActivityWithAnimation();
}
}, 1000);
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void startMapActivityWithAnimation() {
int colorFrom = ContextCompat.getColor(this, R.color.window_background_splash);
int colorTo = ContextCompat.getColor(this, android.R.color.white);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mCircularRevealView.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
}
});
int cx = mCircularRevealView.getWidth() / 2;
int cy = mCircularRevealView.getHeight() / 2;
float finalRadius = Math.max(cx, cy);
Animator circularRevealAnimation = ViewAnimationUtils
.createCircularReveal(mCircularRevealView, cx, cy, 0, finalRadius);
mCircularRevealView.setVisibility(View.VISIBLE);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(200);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
mLogoImage.animate()
.alpha(0.0f)
.setDuration(200)
.setInterpolator(new AccelerateInterpolator())
.start();
}
@Override
public void onAnimationEnd(Animator animation) {
startMapActivity();
}
});
animatorSet.playTogether(colorAnimation, circularRevealAnimation);
animatorSet.start();
}
动画在普通设备上完美运行。我也有一些 Espresso UI 测试,所以我禁用了测试设备上开发人员选项屏幕中的所有动画,现在我得到以下异常:
java.lang.IllegalStateException: Animator has already started, cannot change it now!
at android.view.RenderNodeAnimator.checkMutable(RenderNodeAnimator.java:149)
at android.view.RenderNodeAnimator.setDuration(RenderNodeAnimator.java:324)
at android.view.RenderNodeAnimator.setDuration(RenderNodeAnimator.java:322)
at android.animation.AnimatorSet.updateAnimatorsDuration(AnimatorSet.java:760)
at android.animation.AnimatorSet.getTotalDuration(AnimatorSet.java:1721)
at android.animation.AnimatorSet.forceToEnd(AnimatorSet.java:446)
at android.animation.AnimatorSet.doAnimationFrame(AnimatorSet.java:981)
at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:145)
at android.animation.AnimationHandler.-wrap2(Unknown Source:0)
at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:884)
at android.view.Choreographer.doCallbacks(Choreographer.java:698)
at android.view.Choreographer.doFrame(Choreographer.java:630)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:872)
at android.os.Handler.handleCallback(Handler.java:769)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
您对如何解决此问题有任何建议吗?