2017-02-18 68 views
0

我正在嘗試從不確定水平進度條更改爲確定水平進度條,但確定性進度條無法在不確定的情況下正常工作。Android水平確定進度條未運行

確定一個出現但沒有動作。 請幫助我。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/check" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    <ProgressBar 
    android:id="@+id/my_progressBar" 
    style="@style/Widget.AppCompat.ProgressBar.Horizontal" 
    android:indeterminate="false" 
    android:max="100" 
    android:progress="10"/> 
    </LinearLayout> 
    </android.support.design.widget.CoordinatorLayout> 

而我加入MainActivity.java如下:

ProgressBar progressBar = (ProgressBar) findViewById(R.id.my_progressBar); 
progressBar.setProgress(20); 
+0

進度從20開始並不增加? – Diekrul

+0

@Diekrul是它停留在那裏,並沒有增加 – user3518835

回答

1

我覺得進度不適當增加,因爲你不增量德的進步。如果將setProgress設置爲20,則該欄將保持爲20.

如果要查看運動,則必須逐步增加setProgress。

我希望它的幫助。

0
private int progressStatus = 10;   
new Thread(new Runnable() { 
      public void run() { 

        while (progressStatus < 100) { 

          progressStatus += 5; 

          // 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 300 milliseconds. 
           //Just to display the progress slowly 
           Thread.sleep(300); 
          } catch (InterruptedException e) { 
           e.printStackTrace(); 
          } 


       } 

      } 
     }).start();