I worked out how to do it, by using a runnable I was able to update the progress bar several times a second and so give the sliding effect. The code is 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 increase is the total number of increments that should be done. I can dynamically increase the number of increments from the UI thread to give a smooth effect. The code only works for progress bars that won't need to decrease.
To run it, simply use this code:
mStartTime = System.currentTimeMillis();
incrementor.removeCallbacks(SmoothIncrement);
if(track!=0) {
track -= increase;
}
incrementor.postDelayed(SmoothIncrement, 0);