进度条没有迅速显示进度

时间:2015-07-22 13:00:38

标签: android time progress-bar

我的进度条不是很快。以下是我的代码:

 _progressBar.setMax(30);

    new CountDownTimer(30000, 100) {

        public void onTick(long millisUntilFinished) {

            _progressBar.setProgress((int)millisUntilFinished/1000);
            time.setText(String.valueOf((int) millisUntilFinished / 1000));
        }

        public void onFinish() {

        }
    }.start();

这是我的进度条:

enter image description here

1 个答案:

答案 0 :(得分:0)

我尝试使用值动画设置从0到30缓解。

    //ease from 0 to 30
    ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 30);

    //set time length
    valueAnimator.setDuration(30000);

    //control easing type
    valueAnimator.setInterpolator(new LinearInterpolator());

    valueAnimator.addUpdateListener(new AnimatorUpdateListener()
    {
        Integer valueAnimatorValue = null;

        @Override
        public void onAnimationUpdate(ValueAnimator animation)
        {
            valueAnimatorValue = (Integer) animation.getAnimatedValue();

             _progressBar.setProgress(valueAnimatorValue);
             time.setText(String.valueOf(valueAnimatorValue);
        }
    });

    valueAnimator.start();