How to show an indeterminate horizontal progress bar in android? The animation of the progress bar should start from 0 to 100 and then go back from 100 to 0 continuously. I
Maybe a bit late, but you can do something like this:
<ProgressBar
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="10dp"
android:indeterminate="true"
style="?android:attr/progressBarStyleHorizontal" />
Hope it helps someone!
Use the method setIndeterminate of ProgressBar:
android.widget.ProgressBar bar = new android.widget.ProgressBar(context);
bar.setIndeterminate(true);
But yeah, you could have found this pretty quickly in the developer docs.
http://developer.android.com/reference/android/widget/ProgressBar.html#setIndeterminate%28boolean%29
To expand on Vinoth Answer, here is a ready code:
<ProgressBar
android:id="@+id/progressBarLoadingRecite"
android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
android:minHeight="24dip"
android:layout_marginTop="20dip"
android:indeterminate="true"
android:maxHeight="24dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
In the xml defining your progress bar, you can add
style="@android:style/Widget.ProgressBar.Horizontal"
I already knew that setIndeterminate
will give an infinite horizontal progress bar. But it will be similar to the loading wheel, except that it will be horizontal. If you see my question I was looking for horizontal bar which starts from 0 and goes all the way to 100 (a gradual increase). If you want to achieve this in Android, you must use your progress bar as below:
<ProgressBar
android:id="@+id/progress_horizontal"
android:indeterminateOnly="false"
android:indeterminateDrawable="@drawable/progress_indeterminate_horizontal"
android:progressDrawable="@drawable/progress_horizontal"
android:minHeight="24dip"
android:maxHeight="24dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
As I wanted to change the background of my progress bar, I changed the ProgressDrawable and IndeterminateDrawable. The original drawables are located under frameworks/base/core/res/res/drawable
. Copy them to your project and change the color according to your needs.
Create a thread which updates the progress count and does a Thread.Sleep
. Then it sends the message to the Handler which will update the progress bar in UI thread.