我目前正在使用動態更新ProgressBar
。通過一定的百分比,progessbar設置了不同顏色的drawable。我們目前有一個可繪製的xml中定義的各種彩色剪輯。題爲progressbar_blue_states
的一個詳列如下:ProgressBar.setProgressDrawable不適用於Android 2.3
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background"
android:drawable="@drawable/progressbar_grey">
</item>
<item android:id="@android:id/progress">
<clip android:drawable="@drawable/progressbar_blue" />
</item>
</layer-list>
每當我們需要更新的對話框中,我們調用下面的代碼:
progressBar.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_blue_states));
然而,這不僅不更新的進度,而且還它將完全取消進度條,其中留有空白。但是,如果我在xml中設置了android:progressDrawable="@drawable/progressbar_blue_states"
並取出此setProgressDrawable()
調用,則它會正確加載。我們需要setProgressDrawable根據需要更新顏色。
這個調用在Android 4.0+中運行正常,但是在Android 2.3中我們遇到了一些麻煩。有任何想法嗎?
編輯
這就是我們如何在XML建立進度:
<ProgressBar android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="2dp"
android:indeterminate="false"
android:indeterminateOnly="false"
android:progress="24"
android:max="100"
android:progressDrawable="@drawable/progressbar_red_states" />
您是否嘗試更新'progressbar_blue'的邊界,並將其設置爲進度可繪製? – Luksprog 2013-03-21 10:40:46
你的意思是設定進度量?如果是這樣,那麼在設置drawable後立即執行該操作。 – jbenowitz 2013-03-21 13:56:07
如果你的意思是佈局界限,那麼在xml中,我在上面添加了。 – jbenowitz 2013-03-21 13:58:02