emre1512 / CircleProgressBar

A simple library for creating circular progressbars for Android
Other
113 stars 33 forks source link

Animation Support? #1

Closed nksaroj closed 7 years ago

nksaroj commented 7 years ago

Have you got any sample to animate the progress

ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", 0, currentValue); // see this max value coming back here, we animale towards that value animation.setDuration(1000); //in milliseconds animation.setInterpolator(new DecelerateInterpolator()); animation.start(); This doesn't work

emre1512 commented 7 years ago

Hi,

If you want to set progress, you can use progressbar.setProgress(currentProgress);

currentProgress is the progress value you got from AsyncTask or something similar.

If you want a dummy progressbar that just animates the progress automatically, you can use a handler.

    Handler handle = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            progress += 1;

            // Set progress
            progressBar.setProgress(progress);
            progressBar.setText(String.valueOf(progress));

            if(progress >= 100){
                progressBar.setTextColor("#FF6FD99D");
                progressBar.setText("DONE");
                progressBar.setProgressColor("#FF6FD99D");
                handle1.removeCallbacksAndMessages(runnable);
            }
            handle.postDelayed(runnable, 25); // animate every 25ms
        }
    };
    runnable.run();
nikzdevz commented 2 years ago
ValueAnimator animator = ValueAnimator.ofFloat(from,to);
animator.setDuration(duration);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  @Override
  public void onAnimationUpdate(ValueAnimator valueAnimator) {
    float value = (float)valueAnimator.getAnimatedValue();
    progressBar.setProgress(value);
    progressBar.setText(String.valueOf((int)value));

  }
});
animator.addListener(new AnimatorListenerAdapter() {
  @Override
  public void onAnimationEnd(Animator animation) {
  }

  @Override
  public void onAnimationStart(Animator animation) {
  }
});
animator.setRepeatCount(0);
animator.start();