Android 关于ObjectAnimator 的几种状态

Android 关于ObjectAnimator 的几种状态

  • Started
  • Running
  • Paused
  • End

切换状态的4个方法

方法 状态
start() started, running
pause() paused/started, running
resume() started, running
end() end
cancel() end

获取状态的3个方法

  • isStarted()
  • isRunning()
  • isPaused()

代码展示

void hideTextAnim(){
        anim = ObjectAnimator.ofFloat(fadeText, "alpha", 1.0f, 0f);
        anim.setDuration(2000);
        anim.setRepeatMode(ValueAnimator.REVERSE);
        anim.setRepeatCount(3);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
               Log.d("FadeInFadeOut", "animation start  "
                       +"start:"+anim.isStarted()
               +"  pause:"+anim.isPaused()
               +"  running:"+anim.isRunning());
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                Log.d("FadeInFadeOut", "animation end  "
                        +"start:"+anim.isStarted()
                        +"  pause:"+anim.isPaused()
                        +"  running:"+anim.isRunning());
            }

            @Override
            public void onAnimationPause(Animator animation) {
                Log.d("FadeInFadeOut", "animation pause  "
                        +"start:"+anim.isStarted()
                        +"  pause:"+anim.isPaused()
                        +"  running:"+anim.isRunning());
            }
        });
        anim.start();
    }

注意:

当setRepeatMode(ValueAnimator.INFINITE)时,onAnimationEnd()不会执行。只有当end()被调用时,onAnimationEnd()才执行。


今晚到此结束,Good night!

你可能感兴趣的:(Android动画)