问题
codes
progressBar = (ProgressBar) findViewById(R.id.progressBar);
textView = (TextView) findViewById(R.id.secdelay);
// Start long running operation in a background thread
new Thread(new Runnable() {
public void run() {
while (progressStatus < 15) {
progressStatus += 1;
// Update the progress bar and display the
//current value in the text view
handler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressStatus);
textView.setText(progressStatus+"/"+progressBar.getMax());
}
});
try {
// Sleep for 200 milliseconds.
//Just to display the progress slowly
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
now its loading fine , I want to progress bar for 15ec how to do it ? hope you guys understand what meant . a 15 sec loading progress bar and I saw its jumping the animation, any way to make it smooth . thanks in advance noob question sorry just a learner
回答1:
You can set the max of the progress bar to 15secs*5 = 75 to enable updating smaller 'bites' for a smoother animation.
Then update progress by 1 each 200ms.
progressBar.setMax(75)
while (progressStatus < 75) {
progressStatus += 1;
// Update the progress bar and display the
//current value in the text view
handler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressStatus);
textView.setText(progressStatus+"/"+progressBar.getMax());
}
});
try {
// Sleep for 200 milliseconds.
//Just to display the progress slowly
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Could also sleep only 100ms using a max of 150.
来源:https://stackoverflow.com/questions/23181117/how-make-progress-bar-for-15-sec-loading