如何在 Android 上的 TextVIew 上实现 5 秒内从 0 到 600 的数字动画 [英] How to implement increasing number animation from 0 to 600 in 5 secs on TextVIew on android

查看:14
本文介绍了如何在 Android 上的 TextVIew 上实现 5 秒内从 0 到 600 的数字动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划在特定秒内通过动画在 textView 上实现整数从 0 增加到某个值.例如,在 textview 上显示将数字从 0 增加到 600 持续 5 秒的动画.

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.

我该如何实现?

推荐答案

你可以使用 ValueAnimator 为此:

private void startCountAnimation() {
    ValueAnimator animator = ValueAnimator.ofInt(0, 600);
    animator.setDuration(5000);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        public void onAnimationUpdate(ValueAnimator animation) {
            textView.setText(animation.getAnimatedValue().toString());
        }
    });
    animator.start();
}

这篇关于如何在 Android 上的 TextVIew 上实现 5 秒内从 0 到 600 的数字动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆