我对ProgressBar有问题,因为它没有正确显示它。
代码:
private void setTimer() {
if(np3.getValue() == 0){
time_one = (np1.getValue()) + (np2.getValue() * 60);
totalTimeCountInMilliseconds = time_one * 1000;
} else {
time_two = (np1.getValue()) + (np2.getValue() * 60) + ((np3.getValue() * 3600)-3600);
totalTimeCountInMilliseconds = time_two * 1000;
}
np1.setVisibility(View.GONE);
np2.setVisibility(View.GONE);
np3.setVisibility(View.GONE);
textViewShowTime.setVisibility(View.VISIBLE);
timeseconds = 10 * 1000;
}
private void startTimer() {
countDownTimer = new CountDownTimer(totalTimeCountInMilliseconds, 500) {
@Override
public void onTick(long leftTimeInMilliseconds) {
if (leftTimeInMilliseconds <= timeseconds) {
if(change == false){
textViewShowTime.setVisibility(View.VISIBLE);
textViewShowTime.setTextSize(20);
textViewShowTime.setTextAppearance(getApplicationContext(),
R.style.RedText);
change = true;
} else{
textViewShowTime.setVisibility(View.GONE);
change = false;
}
}
if(np3.getValue() == 0){
Date date = new Date(leftTimeInMilliseconds);
DateFormat formatter = new SimpleDateFormat("mm:ss");
String dateFormatted = formatter.format(date);
textViewShowTime.setText(String.format(dateFormatted));
textViewShowTime.setTextSize(40);
pb.setVisibility(View.VISIBLE);
if(progressStatus <100){
int end_time = 100 / time_one;
progressStatus += end_time;
pb.setProgress(progressStatus);
}
答案 0 :(得分:0)
这是问题所在。
new CountDownTimer(totalTimeCountInMilliseconds, 500)
如果您想模拟1秒,为什么在500 上打勾。应该 1000 。
由于此问题,您的ProgressBar填写速度很快。将其更改为
new CountDownTimer(totalTimeCountInMilliseconds, 1000)
更新此内容。我认为你不需要change
布尔
textViewShowTime.setVisibility(View.VISIBLE);
textViewShowTime.setTextSize(20);
textViewShowTime.setTextAppearance(getApplicationContext(),R.style.RedText);