android - 为什么在动画监听器中调用 .cancel() 会导致 StackOverflowError?

标签 android animation graphics

有什么原因导致我无法在动画监听器中提供的 Animator 上调用 .cancel() 吗?

当我执行以下代码时,出现 StackOverflowError:

        animation.addListener(new ValueAnimator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {
                if (!showCircles)
                    animator.cancel();
            }
        ....

最佳答案

我发现了一个解决方案。

我发现您必须先调用 animator.removeAllListeners();,然后再调用 animator.cancel();。 (对于大多数 4.0+ 设备都是如此,但在 GSIII 上,出于某种原因,您不需要这样做。)

由于某种原因,cancel() 命令导致 onAnimationStart 再次被触发(以无限循环结束)。

关于android - 为什么在动画监听器中调用 .cancel() 会导致 StackOverflowError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13167576/

相关文章:

java - 使用 OutputStreamWriter 写入 : line by line vs all at once

android - 启动另一个 Activity 的 Activity 模式(用于结果)

ios - 呈现 View Controller 以模态方式重置当前 View

graphics - 在网站上创建图表的好方法是什么?

java - Canvas 双缓冲图形不起作用

android - 为什么 onDraw() 会一直被调用?

java - 按钮在 fragment 中不起作用没有错误?

javascript - Canvas - 旋转我的图像(圆圈)

javascript - jquery 显示隐藏面板高度问题

Java 在 XOR 模式下绘制组件不绘制任何内容