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?

citizen conn
  • 15,300
  • 3
  • 58
  • 80
Swifty McSwifterton
  • 2,637
  • 1
  • 30
  • 37
  • 1
    Check this up http://stackoverflow.com/questions/4581812/custom-progress-bar-in-android – vsm Jul 21 '11 at 19:40

2 Answers2

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)

citizen conn
  • 15,300
  • 3
  • 58
  • 80
  • 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. – Swifty McSwifterton Jul 21 '11 at 20:15
  • it shouldn't crash, it's exactly the same as `android:progressDrawable="@drawable/logo"` except the drawable is a ClipDrawable... – citizen conn Jul 21 '11 at 20:19
  • Well, I am using exactly as you have it above, but with the reference to my drawable. Any thoughts? – Swifty McSwifterton Jul 21 '11 at 20:31
  • Have you set your progress bar to be horizontal, like this: style="@android:style/Widget.ProgressBar.Horizontal" – citizen conn Jul 21 '11 at 20:41
  • I have it set like this: style="?android:attr/progressBarStyleHorizontal". – Swifty McSwifterton Jul 21 '11 at 20:48
  • Here's my gist, this works for me: https://gist.github.com/5c08cd2e99b1b572b497/83a00627dc68862b2c25aa27fc1ad346ad41ac6e – citizen conn Jul 21 '11 at 21:13
0

Try to use:

progressBar.setIndeterminateDrawable(getResources()...etc)
iBog
  • 2,245
  • 1
  • 20
  • 15