2011-04-12 29 views
5

我有一個ProgressBar的佈局(實際上它是一個SeekBar,但ProgressBar發生同樣的問題)。它工作正常,直到我開始動畫整個佈局,將其翻譯下來。 ProgressBar在動畫期間繼續按預期工作,但是當動畫完成時(並且我使用Animation.setFillAfter(true))將佈局凍結在動畫的最後位置),ProgressBar停止正確更新,而不是僅僅一小行在bar的頂部保持更新,而progressBar的底部保持凍結(其水平progressBar)。ProgressBar在動畫後沒有正確更新

一些代碼: 佈局與進度:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/video_buttons" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|left"> 
<SeekBar 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/progressbar_Horizontal" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:max="100" 
/> 

這裏就是我定義動畫:

Animation a = AnimationUtils.loadAnimation(this, R.anim.translate_down); 
a.setFillAfter(true); 

這裏是我開始對整個佈局動畫:

View vv = p.findViewById(R.id.video_buttons); 
vv.startAnimation(anim); 
+0

沒有足夠的代碼。你應該發佈一個完整的測試用例。 – 2011-06-26 21:54:25

回答

0

我的第一個想法是,你可能會無意中使用th e「android:secondaryProgress」屬性。

除此之外,如果你在一個單獨的線程運行的這種情況,請確保您使用以下:

activity.runOnUiThread(new Runnable() // 
      { 
       public void run() // 
       { 
        int newProgressVal = Integer 
          .parseInt((String) syncProgressNumber.getText()) + 1; 
        syncProgress.incrementProgressBy(1); 
        syncProgressNumber.setText(String 
          .valueOf(newProgressVal)); 
       } 
      }); 

UI線程不是線程安全的,所以你不能更新UI來自其他線程。

希望這會有所幫助!