June 23, 2009

Using a Horizontal Progress Bar in Android

"I was working on my Android downloader application yesterday, when I ran into a bit of a snag. I wanted to display a list of downloads (similar to the Firefox downloads window). Each item in the list should show the file name and a horizontal progress bar. I started to implement this, and several hours later stumbled upon the archaic solution. I wanted to share this, both to help anybody who may be trying to do something similar, and also to illustrate how the lack of good documentation is hurting aspiring Android developers.

I thought that I could put a ProgressBar instance in my xml, set it to be indeterminate, give it a max and a value, and be done. However, it wasn't nearly that easy. After a few hours of hunting on Google and the Android Groups, I stumbled upon the solution in an online preview of The Busy Coder's Guide to Android Development. In short, I had to set the following on my ProgressBar's XML:
style="?android:attr/progressBarStyleHorizontal"

WTF?

" http://bytecrafter.blogspot.com/2008/12/using-horizontal-progress-bar-in.html

to get horizontal progressbar just put

<ProgressBar
android:id="@+id/ProgressBar01"
android:indeterminateOnly="false"
android:progressDrawable="@android:drawable/progress_horizontal"
android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
android:minHeight="20dip"
android:maxHeight="20dip" android:layout_width="fill_parent"></ProgressBar>


into your \res\layout\main.xml

4 comments:

  1. YOU SAVED MY SANITY

    ReplyDelete
  2. It really Helped me.Thank U.

    ReplyDelete
  3. can we use image to show the progress, instead of using colours ??

    ReplyDelete
  4. Hello, i think that i saw you visited my web site so i came to
    “return the favor”.I'm trying to find things to improve my site!I suppose its ok to use a few of your ideas!!

    ReplyDelete