我似乎无法理解如何填充进度条。我正在使用倒数计时器更新进度条上的进度,使其倒计时直到达到零。现在我想要扭转进展并让它从零开始并填满,但我将如何实现这一目标呢?
public class theCountDownTimer extends CountDownTimer
{
public theCountDownTimer(long millisInFuture, long countDownInterval)
{
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long millisUntilFinished)
{
int progress = (int) (millisUntilFinished/100);
progressBarCounter.setProgress(progress);
}
@Override
public void onFinish()
{
Button nextInstance = (Button) findViewById(R.id.run);
nextInstance.performClick();
}
}
答案 0 :(得分:1)
progressBar
默认最大值为100
。我想你希望它能在每个刻度线上前进,所以在theCountDownTimer
里你应该定义:
progressBarCounter.setMax((int) millisInFuture/1000);
这样,如果你计算80秒(= 80,000mS),那么该栏的范围将在0到80之间。
接下来,您可以使用incrementProgressBy (int diff)
方法:
public class theCountDownTimer extends CountDownTimer
{
public theCountDownTimer(long millisInFuture, long countDownInterval)
{
super(millisInFuture, countDownInterval);
progressBarCounter.setMax((int) millisInFuture/1000);
progressBarCounter.setProgress(0); //Reset the progress
}
@Override
public void onTick(long millisUntilFinished)
{
progressBarCounter.incrementProgressBy(1);
}
@Override
public void onFinish()
{
Button nextInstance = (Button) findViewById(R.id.run);
nextInstance.performClick();
}
}
我猜你在这里也有错误 -
int progress = (int) (millisUntilFinished/100);
您的意思是除以1000
代替100
吗?