现在,我已经创建了进度条,我想为进度条分配时间(例如 2 分钟) 并且用户必须能够在运行进度条时看到时间。 我们如何才能做到这一点?
最佳答案
您可以使用 CountDownTimer 更新 ProgressBar
bar = (ProgressBar) findViewById(R.id.progress);
bar.setProgress(total);
int twoMin = 2 * 60 * 1000; // 2 minutes in milli seconds
/** CountDownTimer starts with 2 minutes and every onTick is 1 second */
cdt = new CountDownTimer(twoMin, 1000) {
public void onTick(long millisUntilFinished) {
total = (int) ((dTotal / 120) * 100);
bar.setProgress(total);
}
public void onFinish() {
// DO something when 2 minutes is up
}
}.start();
关于java - 在 Android 的 ProgressBar 上显示时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5113960/