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

后端 未结 5 1966
野的像风
野的像风 2020-12-12 18:24

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

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 18:52

    Take a look at this simple solution:

    public void animateTextView(int initialValue, int finalValue, final TextView  textview) {
        ValueAnimator valueAnimator = ValueAnimator.ofInt(initialValue, finalValue);
        valueAnimator.setDuration(1500);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
               textview.setText(valueAnimator.getAnimatedValue().toString());
            }
        });
        valueAnimator.start();
    
    }
    

提交回复
热议问题