I developed how to do this using runnable, I was able to update the progress bar several times per second and thus give a sliding effect. Code below:
private Runnable SmoothIncrement = new Runnable() { public void run() { final long start = mStartTime; long millis = SystemClock.uptimeMillis() - start; if(track!=increase) { if((pb.getProgress()==100)&&(count<target)) { pb.setProgress(0); } pb.incrementProgressBy(1); track++; incrementor.postAtTime(this, start + millis); } else { incrementor.removeCallbacks(this); } } };
Here, "track" keeps track of how many increments have been done, and the increase is the total number of steps that must be taken. I can dynamically increase the number of increments from the user interface thread to provide a smooth effect. The code only works for progress indicators that do not need to be reduced.
To run it, just use this code:
mStartTime = System.currentTimeMillis(); incrementor.removeCallbacks(SmoothIncrement); if(track!=0) { track -= increase; } incrementor.postDelayed(SmoothIncrement, 0);
Todd Davies May 24 '11 at 11:58 a.m. 2011-05-24 11:58
source share