Leon Li Leon Li - 1 year ago 189
Android Question

How to implement increasing number animation from 0 to 600 in 5 secs on TextVIew on android

I plan to implement integer number increase on textView from 0 to some value with animation within certain seconds.
e.g show animation which increase number from 0 to 600 on textview for 5 seconds duration.

How can I implement this?

Thanks in advance!

Answer Source

You could use the ValueAnimator for that:

private void startCountAnimation() {
    ValueAnimator animator = new ValueAnimator();
    animator.setObjectValues(0, 600);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        public void onAnimationUpdate(ValueAnimator animation) {
            textView.setText("" + (int) animation.getAnimatedValue());