1

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

2 Answers 2

2

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)

6
  • I tried that, but I the app is crashing. I am getting this error: 07-21 15:14:38.492: ERROR/AndroidRuntime(30806): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class android.widget.ProgressBar Any ideas? Thanks. Jul 21, 2011 at 20:15
  • it shouldn't crash, it's exactly the same as android:progressDrawable="@drawable/logo" except the drawable is a ClipDrawable... Jul 21, 2011 at 20:19
  • Well, I am using <ProgressBar android:progressDrawable="@drawable/progress_clip"... with the <clip> exactly as you have it above, but with the reference to my drawable. Any thoughts? Jul 21, 2011 at 20:31
  • Have you set your progress bar to be horizontal, like this: style="@android:style/Widget.ProgressBar.Horizontal" Jul 21, 2011 at 20:41
  • I have it set like this: style="?android:attr/progressBarStyleHorizontal". Jul 21, 2011 at 20:48
0

Try to use:

progressBar.setIndeterminateDrawable(getResources()...etc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.