简体   繁体   中英

Android Indeterminate ProgressBar : Animating custom drawable

I currently have an Indeterminate ProgressBar

 <ProgressBar
        android:id="@+id/progressBar2"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="#B8A1A1"
        android:indeterminate="true"
        android:indeterminateDuration="1000"/>

When I set a custom drawable using a gradient of colours, the progress bar no longer moves. It's a stationary bar.

val colors: IntArray = intArrayOf(Color.parseColor("#a8bded"),Color.parseColor("#0a3cad"),Color.parseColor("#a8bded"))
val gd = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,colors)
progressBar2.indeterminateDrawable = gd

How do I make the custom progressdrawable animate as usual?

Setting useLevel=true fixed it.

val colors: IntArray = intArrayOf(Color.parseColor("#a8bded"),Color.parseColor("#0a3cad"),Color.parseColor("#a8bded"))
val gd = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,colors)
gd.useLevel=true
progressBar.indeterminateDrawable = gd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM