2014-11-09 184 views
0

我在此處使用此代碼來循環和更新自定義進度欄上的進度。減慢進度條進度

class MyThreadRunner implements Runnable { 
     // @Override 
    int count = 0; 
     public void run() { 
      try { 
      while (count < 90) { 
       Thread.sleep(10); 
       count += 1; 
       progressBar.setProgress(count); 
       progressBar.setText(count + "%"); 
      } 
       } catch (InterruptedException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

       } 
}; 

當它靠近末端時我希望它開始減慢,這是可能的,而不必再做一個while循環嗎?

回答

1

爲什麼不改變超過90的值的睡眠時間?

class MyThreadRunner implements Runnable { 
     // @Override 
    int count = 0; 
     public void run() { 
      try { 

      while (count < 100) { 

       //500 is half a second... 
       int sleepTime = count < 90 ? 10 : 500; 
       Thread.sleep(sleepTime); 

       count += 1; 
       progressBar.setProgress(count); 
       progressBar.setText(count + "%"); 
      } 
       } catch (InterruptedException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

       } 
};  
0
class MyThreadRunner implements Runnable { 
     // @Override 
    int count = 0; 
    int sleepTime = 0; 
     public void run() { 

      while (count < 100) { 
       sleepTime = count < 90 ? 10 : 100; 
       Thread.sleep(sleeptime); 

      } 


};