2014-04-20 3 views
0

코드 지금 진행 막대를 15 초 동안로드하는 방법은 무엇입니까?

progressBar = (ProgressBar) findViewById(R.id.progressBar); 
      textView = (TextView) findViewById(R.id.secdelay); 
      // Start long running operation in a background thread 
      new Thread(new Runnable() { 
       public void run() { 
        while (progressStatus < 15) { 
         progressStatus += 1; 
         // Update the progress bar and display the 

         //current value in the text view 
         handler.post(new Runnable() { 
          public void run() { 
           progressBar.setProgress(progressStatus); 
           textView.setText(progressStatus+"/"+progressBar.getMax()); 
          } 
         }); 
         try { 
          // Sleep for 200 milliseconds. 

          //Just to display the progress slowly 
          Thread.sleep(1500); 
         } catch (InterruptedException e) { 
          e.printStackTrace(); 
         } 
        } 
       } 
      }).start(); 

의 로딩 벌금, 나는 그것을 수행하는 방법 15ec 위해 줄을 진행 하시겠습니까? 너희들이 의미하는 바를 이해하기를 바란다. 진행 막대를로드하는 15 초와 나는 그것을 부드럽게하는 어떤 방법이라도 그 애니메이션을 뛰어 넘는 것을 보았다. 미리 감사드립니다. 멍청한 질문 죄송합니다. 그냥 학습자입니다.

답변

0

매끄러운 애니메이션을 위해 작은 비트를 업데이트 할 수 있도록 진행 막대의 최대 값을 15 초 * 5 = 75로 설정할 수 있습니다.

그런 다음 각 200ms마다 1 씩 진행률을 업데이트하십시오.

progressBar.setMax(75) 
while (progressStatus < 75) { 
    progressStatus += 1; 
    // Update the progress bar and display the 

    //current value in the text view 
    handler.post(new Runnable() { 
     public void run() { 
      progressBar.setProgress(progressStatus); 
      textView.setText(progressStatus+"/"+progressBar.getMax()); 
     } 
    }); 
    try { 
     // Sleep for 200 milliseconds. 

     //Just to display the progress slowly 
     Thread.sleep(200); 
    } catch (InterruptedException e) { 
     e.printStackTrace(); 
    } 
} 

도 만이 100ms 150

+0

의 최대 수를 사용하는자는 다른 용액 .. (progressStatus <100) ..progressStatus + = 1; 와 Thread.sleep (150); 이 상태에서 진행률 표시 줄은 15 초 안에 모두 실행됩니다. 어떻게 도와 주셔서 감사합니다. –

관련 문제