onAnimationEnd()被调用了两次 [英] onAnimationEnd() called twice

查看:464
本文介绍了onAnimationEnd()被调用了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在更新版本23的sdk 27​​之后,在调用时在下面的代码中两次触发了onAnimationEnd这个问题。 onAnimationStart仅被调用一次,并且onAnimationRepeat没有按预期方式被调用。现在,在应用程序中,当用户一次按下后退按钮时,将向后退两步。

After updating the build sdk 27 from 23 came across this issue of onAnimationEnd firing twice in the code below when called. onAnimationStart is called only once and onAnimationRepeat is not called as expected. Now in the app when the user presses the back button one time, they are taken two steps back.

gradle中的所有库都使用最新的27.0.2。 。这段代码过去在sdk 23中正常工作。我们的最小目标是16。

All the libraries in gradle are using 27.0.2 which is the latest. This code used to work fine in sdk 23. Our min target is 16.

我正在使用isAnimating标志进行变通,但想找到底层的

I'm using a work around by using a isAnimating flag but would like to find the underlying cause which could be affecting other areas of the app.

@Override
public void onBackPressed() {
        Animation slideOutRightAnimation = AnimationUtils.loadAnimation(this, R.anim.slide_out_right);
        slideOutRightAnimation.setFillAfter(true);
        slideOutRightAnimation.setAnimationListener(new AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                isAnimating = true;
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if(isAnimating) { // Fix
                    getSupportFragmentManager().popBackStackImmediate();
                }
                isAnimating = false;
            }
        });
        fragmentToPopView.clearAnimation();
        fragmentToPopView.startAnimation(slideOutRightAnimation);


推荐答案

请尝试

开始动画之前

fragmentToPopView.clearAnimation();

fragmentToPopView.clearAnimation();

这篇关于onAnimationEnd()被调用了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆