我想在Android Studio中创建一个自定义倒数计时器,但我希望它的持续时间/间隔在2个计数之间,而不是正常的倒数计时器。请帮帮我。
答案 0 :(得分:1)
通过设置countDownInterval参数,可以更改两个刻度之间的间隔:
private CountDownTimer mCountDownTimer = new CountDownTimer(millisInFuture, countDownInterval) {
public void onTick(long millisUntilFinished) {
// do sth here...
}
public void onFinish() {
// do sth here...
}
};
例如,通过将其设置为2000,计时器每2秒滴答一次。 要启动或停止计时器:
mCountDownTimer.start();
mCountDownTimer.cancel();
答案 1 :(得分:1)
您可以尝试以下方法:
new CountDownTimer(30000, 1000) {//initial interval is one second
private int i = 0;
public void onTick(long millisUntilFinished) {
i++;
if (i % 2 == 0) {//if you want a longer interval to do something
//practical interval is now two seconds, change as you want.
......
}
}
public void onFinish() {
.....
}
}.start();