2016-08-30 157 views
-1

我有ProgressBar的問題,因爲它沒有正確顯示它。Progressbar無法正確顯示

Video

代碼:

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

這是問題所在。

new CountDownTimer(totalTimeCountInMilliseconds, 500) 

如果你想模擬1秒你爲什麼打勾500。它應該是。

由於這個問題您的ProgressBar填充得很快。將其更改爲

new CountDownTimer(totalTimeCountInMilliseconds, 1000) 

更新該內容。我不認爲你需要change布爾

textViewShowTime.setVisibility(View.VISIBLE); 
textViewShowTime.setTextSize(20); 
textViewShowTime.setTextAppearance(getApplicationContext(),R.style.RedText); 
+0

我已經改變了,但後來我曾與閃爍的文字一個問題,說這是不是我想要的:/ – tomecki

+0

我改變,現在有這樣的事情 https://drive.google.com/file/d/0B3LWRfNDCNdBSHB6RGRxTUYydXc/view?usp=sharing – tomecki

+0

你能否更新你的問題。 –