问题
I have a logo image that I would like to use in my progress bar. Each time an image is downloaded, my progress bar creeps up using a blue bar. However, I would prefer that it slowly display my logo image, one bit at a time. I tried:
android:progressDrawable="@drawable/logo"
but that just set the entire progress bar immediately to my image. I also tried setting it dynamically with:
progressBar.setProgressDrawable(getResources()...etc)
but this just left me with no view and a black empty space.
Can be done?
回答1:
Create a ClipDrawable and set your progressDrawable in XML to point to that ClipDrawable XML which looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/logo"
android:clipOrientation="horizontal"
android:gravity="left" />
</clip>
Then in the onProgress just call yourDrawable.setLevel(progressAmount)
回答2:
Try to use:
progressBar.setIndeterminateDrawable(getResources()...etc)
来源:https://stackoverflow.com/questions/6781675/how-to-make-a-progress-bar-use-an-image-to-show-progress-instead-of-using-a-colo