我正在使用一个循环进度条,它有一个倒数计时器,持续10分钟。 Progressbar工作正常,但不顺畅.Below是我的循环进度条的代码。
public class MainActivity extends AppCompatActivity {
ProgressBar barTimer;
CountDownTimer countDownTimer;
TextView textTimer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
barTimer = findViewById(R.id.barTimer);
barTimer.setProgress(100);
barTimer.setMax(100);
startTimer(10);
}
private void startTimer(final int minuti) {
countDownTimer = new CountDownTimer(60 * minuti * 1000, 1000) {
@Override
public void onTick(long leftTimeInMilliseconds) {
long seconds = leftTimeInMilliseconds / 6000;
barTimer.setProgress((int)seconds);
}
@Override
public void onFinish() {
}
}.start();
}
}
任何人都可以帮助我如何使进度条顺利进行。
答案 0 :(得分:1)
我只是将进度条划分为1000个部分并且每100毫秒调用一次以便它会更加流畅
public class MainActivity extends AppCompatActivity {
ProgressBar barTimer;
CountDownTimer countDownTimer;
TextView textTimer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
barTimer = findViewById(R.id.barTimer);
barTimer.setMax(1000);
startTimer(10);
}
private void startTimer(final int minuti) {
countDownTimer = new CountDownTimer(60 * minuti * 1000, 100) {
@Override
public void onTick(long leftTimeInMilliseconds) {
long seconds = leftTimeInMilliseconds / 600;
barTimer.setProgress((int)seconds);
}
@Override
public void onFinish() {
}
}.start();
}
}