Clip your "on" drawable:
over your "off" drawable:
by using res/drawable/custom_progress_drawable.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Background -->
<item
android:id="@android:id/background"
android:drawable="@drawable/custom_progress_bar_off"/>
<!-- Secondary progress - this is optional -->
<item android:id="@android:id/secondaryProgress">
<clip android:drawable="@drawable/custom_progress_bar_secondary" />
</item>
<!-- Progress -->
<item android:id="@android:id/progress">
<clip android:drawable="@drawable/custom_progress_bar_on" />
</item>
</layer-list>
From an Activity
, use
Drawable progressDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.custom_progress_drawable, getTheme());
myProgressBar.setProgressDrawable(progressDrawable);
or in xml, use
android:progressDrawable="@drawable/custom_progress_drawable"
And here's the result when using android:max="10"
in xml:
It's a little bit off, but you could use setMax()
with something more like 10000
and do some offsetting calculations when calling setProgress()
to make it cleaner.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…