Detecting when ValueAnimator is done

后端 未结 3 1662
清酒与你
清酒与你 2021-02-02 05:37

Right now I am detecting the end of my ValueAnimator by checking when the progress has reached 100...

//Setup the animation
ValueAnimator anim = ValueAnimator.of         


        
相关标签:
3条回答
  • 2021-02-02 06:06

    i logged results for ValueAnimator and saw that it does not generate all values, just look this:

    03-19 10:30:52.132 22170-22170/com.sample.project D/View:  next = 86
    03-19 10:30:52.148 22170-22170/com.sample.project D/View:  next = 87
    03-19 10:30:52.165 22170-22170/com.sample.project D/View:  next = 89
    03-19 10:30:52.181 22170-22170/com.sample.project D/View:  next = 91
    03-19 10:30:52.198 22170-22170/com.sample.project D/View:  next = 92
    03-19 10:30:52.215 22170-22170/com.sample.project D/View:  next = 94
    03-19 10:30:52.231 22170-22170/com.sample.project D/View:  next = 96
    03-19 10:30:52.248 22170-22170/com.sample.project D/View:  next = 97
    03-19 10:30:52.265 22170-22170/com.sample.project D/View:  next = 99
    03-19 10:30:52.282 22170-22170/com.sample.project D/View:  next = 101
    

    So asking you questuion i say to check value isn't correct way. You need add onAnimationEnd listener, described in the post

    0 讨论(0)
  • 2021-02-02 06:07

    On Kotlin with Android KTX (Core):

    animator.doOnEnd {
        // done
    }
    
    0 讨论(0)
  • 2021-02-02 06:09

    You can do something like:

    ValueAnimator anim = ValueAnimator.ofInt(progress, seekBar.getMax());
    anim.setDuration(Utility.setAnimationDuration(progress));
    anim.addUpdateListener(new AnimatorUpdateListener() 
    {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) 
        {
            int animProgress = (Integer) animation.getAnimatedValue();
            seekBar.setProgress(animProgress);
        }
    });
    anim.addListener(new AnimatorListenerAdapter() 
    {
        @Override
        public void onAnimationEnd(Animator animation) 
        {
            // done
        }
    });
    anim.start();
    
    0 讨论(0)
提交回复
热议问题