AnimatorListener - onAnimationEnd不起作用

时间:2016-12-22 17:05:34

标签: android animation

在我的APP中我使用https://github.com/semanticer/TurriType - 它用于“类型编写者”文本动画。

它有效(大部分时间,可能会更好....),但我的AnimatorListener不起作用(因此onAnimationStart / onAnimationEnd也不起作用)。

在我的活动(不是MainActivity)中,我有这个:

        Animator.AnimatorListener toastListener = new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

            Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_LONG).show();

        }

        @Override
        public void onAnimationEnd(Animator animation) {

            Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_LONG).show();

            mCardViewChoice1.setVisibility(View.VISIBLE);
            mCardViewChoice2.setVisibility(View.VISIBLE);

        }

        @Override
        public void onAnimationCancel(Animator animation) {

            Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_LONG).show();

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

            Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_LONG).show();

        }
    };

    animator = TurriType.write(pageText).withListener(toastListener).into(mTextView);
    mTextView.setText("");
    animator.start();

动画效果很好,但我没有收到Toasts,所以我无法使用它。

有什么想法吗?谢谢:)

1 个答案:

答案 0 :(得分:1)

根据您提供的来源,这似乎是预期的行为。

这是你的电话 animator = TurriType.write(pageText).withListener(toastListener).into(mTextView);

如果你看TypeAnimationFactory的第44行,你会看到它没有添加提供的animationListener,如果已经有插值器的话。

最后,如果你查看TurriType.write(...)(第56行here)方法,你会看到它使用LinearInterpolator创建一个默认的“WriteRequest”对象。

因此,动画将会起作用,但由于您的侦听器从未设置过,因此您无法获得回调。

相关问题