Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ProgressBar stop spinning?

When I add horizontal ProgressBar it behaves as expected -- I set the progress value and it shows it.

However when I add ProgressBar (circular) it spins. And that's it. In such form it is more "please wait" indicator, that any progress bar, because progress value is not shown.

So my question is (assuming Progress in name means progress) -- how to stop spinning and shows progress value? For example if I set max to 100, and value to 50 I would expect to see half-circle arc.

In other words how to make circular ProgressBar to behave like horizontal ProgressBar, with only exception of the shape?

like image 997
greenoldman Avatar asked Oct 16 '12 17:10

greenoldman


People also ask

How do I stop ProgressBar?

You want to stop the progressDialog or change its UI not to be circular? You can set your progressbar's visibility to invisible or gone through progressbar. setVisibility(View. INVISIBLE); or progressBar.

What is ProgressBar indeterminate?

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

What is a difference between SeekBar and ProgressBar in Android?

In Android, SeekBar is an extension of ProgressBar that adds a draggable thumb, a user can touch the thumb and drag left or right to set the value for current progress. SeekBar is one of the very useful user interface element in Android that allows the selection of integer values using a natural user interface.


1 Answers

I know that this is an old post but I ran into the same issue and I make it work.

It is actually easier than you think, you have to set a custom progress in an xml file inside your drawable folder and handle the attributes "fromDegrees" and "toDegrees" from the < rotate > tag:

This is the code for custom_progress.xml (you can customize yours as you like but you must not modify "fromDegrees" and "toDegrees")

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">     <item android:id="@android:id/background">         <shape             android:innerRadiusRatio="2.3"             android:shape="ring"             android:useLevel="false"             android:type="sweep"             android:thicknessRatio="15.0">             <solid android:color="#0099ff"/>         </shape>     </item>     <item android:id="@android:id/progress">         <rotate             android:pivotX="50%"             android:pivotY="50%"             android:fromDegrees="-90"             android:toDegrees="-90">             <shape                 android:innerRadiusRatio="2.3"                 android:shape="ring"                 android:angle="0"                 android:type="sweep"                 android:thicknessRatio="15.0">                 <solid android:color="#e0e0e0"/>             </shape>         </rotate>     </item> </layer-list> 

And for your progress bar you have to set this attributes:

<ProgressBar     android:id="@+id/progressbar"     style="?android:attr/progressBarStyleHorizontal"     android:layout_width="100dp"     android:layout_height="100dp"     android:indeterminate="false"     android:max="100"     android:progress="20"     android:progressDrawable="@drawable/custom_progress" /> 

What is happening here is that the progress will start in degree -90 which for me is the top side of the progress bar view and towards the right and it will continue towards the same degree, this will make the view progress to start and end in the same degree.

NOTE: If you set 0 for both "fromDegrees" and "toDegrees" the progress will start from the right side of the circle.

Hope it helps people with the same requirement.

like image 192
Fabian Almaraz Avatar answered Sep 22 '22 20:09

Fabian Almaraz