How to show a Horizontal Android Indeterminate Progress Bar


Question: 

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.




5 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.

 

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"
 

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!

 

More Articles


WPF c# window navigation

i got 2 window , i want to navigate from one another but i when i debug it , it shows that nav is null , why is that so? Does it suppose to be null? because i used the same way to navigate in the past and it work and i try it now , it doesn't work. But if i put nav == null , it says nav.Navigate(n

jquery - CSS for toolbar with UI Slider centered between left and right buttons

I'm attempting to create a 100% width toolbar. This toolbar needs to have a variable number of buttons aligned to the left side, as well as a variable number of buttons aligned to the right. That's the easy part.But now I want to put a jQuery UI slider in the center that takes up the full remaining

formatting - Excel 2007 floating format toolbar customisation

Is it possible in Excel 2007 to customise the floating format bar that is shown when you right-click on a cell? To avoid confusion, I don't mean the "Cell" commandbar menu, but the second floating toolbar with formatting buttons.e.g. is it possible to add a Styles dropdown, or have any other text al


wpf - Giving a stackPanel the same LinearGradientBrush as the toolbar has by default

I have two ToolBars side by side (I had to do that so I could align buttons right and left)But now, I have to add some text that can be aligned right left or center between both toolbars. I added the text in a TextBlock inside a StackPanel disposed on a Grid at the second position (between the toolb

compact framework - Toolbar button sizes in windows mobile 6.5.3

We have a VB.net CF2.0 Apllication that up until now has run on windows mobile platforms from 2003 to 6.0 without any major issues. Our current team use HP iPAQ devices running winodws 6.0 and everything runs fine. There is a good, hardware related reson why we use these devices. We are looking to u

WPF Application - Visual Studio 2008 Toolbox Not Loading Correctly!

I'm pretty new to WPF however i've got a solid understanding of WindowsForms. When I create a new WinForms application in Visual Studio the Toolbox displays a huge list of different controls that can be used for developing the program.However, this is only the second time i've started to design stuf


c# - Datagrid Binding in code behind versus DataGrid binding in XAML

I am testing WPF and bindings.I have a demo which is working fine with my bindings done in the code-behind.Here is my XAML code and C# code.<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/wi

Debugging with PhpStorm locally

Kind of a noob question. I'm uploading to a remote server. I've been advised to debug locally (versus remotely). How am I to pull up my files in a browser, then use the debugging tools in PhpStorm? As it stands, my remote host (in PhpStorm) is configured. I've done my own research but can't seem to

xamarin.forms - How to add background image to grid layout in xamarin forms?

I have four rows and two columns.I need to display the background image to full grid.Please provide me solution.I had referred this creating background image in content page link:Xamarin Forms - how to add background image to a content page.But how to set background image to grid layout.

c# - Custom Control, bind to code behind

Having trouble binding to the data in my code behind for my custom control. Obviously I have got to use the Generic.xaml to style my control, and I want to bind to the data in my control UserProfile.cs. This is the code behind:using System;using System.Windows;using System.Windows.Controls;namespace