Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a Horizontal Android Indeterminate Progress Bar

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 am not looking for the wheel progress bar.

like image 884
Vinoth Avatar asked Jun 23 '11 04:06

Vinoth


People also ask

How do I make my progress bar horizontal android?

In Android, by default a progress bar will be displayed as a spinning wheel but If we want it to be displayed as a horizontal bar then we need to use style attribute as horizontal. It mainly use the “android. widget. ProgressBar” class.

How do you make an indeterminate progress bar?

By default, every progress bar (created using one of several JProgressBar constructors) is determinate. You may make any JProgressBar indeterminate using the setIndeterminate method: pb. setIndeterminate(true);

What is indeterminate in progress bar?

An indeterminate ProgressBar shows a cyclic animation without an indication of progress.


1 Answers

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.

like image 133
Vinoth Avatar answered Sep 20 '22 21:09

Vinoth