Have you any idea how to make a circular progress bar like the one of Google Fit application? Like the image below.
-
7I've actually made something like this recently. This might be a helpful starting point? https://github.com/daentech/CircularDemo – daentech Nov 30 '14 at 12:50
-
1Anyone got an answer where the edges of the loading part are rounded like in the example? – Siebe Dec 01 '14 at 18:32
-
Refer here : http://stackoverflow.com/questions/23509065/showing-progress-in-the-circle – WannaBeGeek Dec 02 '14 at 16:50
-
1@Siebe you can use the library that I mentioned in my answer .It can be customized to get loading part as you want. – WannaBeGeek Dec 02 '14 at 17:04
-
2maybe this can point you in the right direction https://github.com/grmaciel/two-level-circular-progress-bar – gmemario Oct 13 '15 at 23:26
-
Sigh... Why did google did not even bother to add it on their official SDK? – Neon Warge Sep 14 '16 at 09:09
-
you can use something like this https://github.com/emre1512/CircleProgressBar – Zapdos Aug 04 '17 at 08:09
-
https://github.com/lopspower/CircularProgressBar and with it you can use: `app:cpb_corner_style="round"` for rounded corners – mtrakal Feb 22 '18 at 15:00
2 Answers
It's easy to create this yourself
In your layout include the following ProgressBar
with a specific drawable (note you should get the width from dimensions instead). The max value is important here:
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:max="500"
android:progress="0"
android:progressDrawable="@drawable/circular" />
Now create the drawable in your resources with the following shape. Play with the radius (you can use innerRadius
instead of innerRadiusRatio
) and thickness values.
circular (Pre Lollipop OR API Level < 21)
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:thickness="3.8sp" >
<solid android:color="@color/yourColor" />
</shape>
circular ( >= Lollipop OR API Level >= 21)
<shape
android:useLevel="true"
android:innerRadiusRatio="2.3"
android:shape="ring"
android:thickness="3.8sp" >
<solid android:color="@color/yourColor" />
</shape>
useLevel is "false" by default in API Level 21 (Lollipop) .
Start Animation
Next in your code use an ObjectAnimator
to animate the progress field of the ProgessBar
of your layout.
ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", 0, 500); // see this max value coming back here, we animate towards that value
animation.setDuration(5000); // in milliseconds
animation.setInterpolator(new DecelerateInterpolator());
animation.start();
Stop Animation
progressBar.clearAnimation();
P.S. unlike examples above, it give smooth animation.

- 8,731
- 3
- 79
- 73

- 15,176
- 7
- 58
- 83
-
is there a way to add text in the center of the progress bar? – gursahib.singh.sahni Apr 29 '15 at 07:24
-
Yes, there are multiple ways to add text between them. Shape are just drawables. – Murtaza Khursheed Hussain Apr 29 '15 at 07:27
-
secondly is there a way to change the white color of progress bar over which our color comes to show the progress? – gursahib.singh.sahni Apr 29 '15 at 08:10
-
-
-
-
-
@MurtazaKhursheedHussain Is there any way to make end of arc rounded? – Praveena Jul 23 '15 at 19:28
-
I implemented it and it's working great. But pausing and resuming animation is not available in API < 19. Have any solution for this? – Fahid Nadeem Aug 18 '15 at 08:41
-
@FahidNadeem there is no support for pause/resume animation in Api level < 19. For above that you can use `PausableAlphaAnimation` class. – Murtaza Khursheed Hussain Aug 18 '15 at 09:24
-
-
AFAIK no. but you can create a custom implementation for this. – Murtaza Khursheed Hussain Aug 18 '15 at 13:14
-
Just one clarification for those who may encounter the same problem that I had: in ObjectAnimator.ofInt(yourId, "progress", 1, 500); you have to substitute "yourId" with your view, not the id of your view. So "findViewById(R.id.yourId)", not only "R.id.yourId". Hope it may help! – aveschini Sep 10 '15 at 08:52
-
Hi, could you please tell me, how could I achieve this code **getProgressDrawable().setColorFilter(Color.GREEN, Mode.SRC_IN);** – OnePunchMan Sep 30 '15 at 19:28
-
@MurtazaKhursheedHussain also with your code the greyish part in the OP circular progress bar is not visible, its transparent. Please tell me how to make it visible. – OnePunchMan Sep 30 '15 at 19:34
-
1delete the style in progressbar - "progressbarstyleHorizontal", this is how you make it visible – ERJAN Oct 26 '15 at 05:29
-
Salam, thank you for your solution! Although not relevant to the OP but is there anyway I can make the progress continuous instead of going from 0 to 100%. For example it could show a spinning circle and when the task finishes the circle would disappear. – Muhammad Ali Oct 27 '15 at 04:32
-
@SnowTauren it is relevant to the OP and thats the reason I posted the answer. Yes, you can alway tweak it. – Murtaza Khursheed Hussain Oct 27 '15 at 04:33
-
@MurtazaKhursheedHussain, no I meant what i'm asking is irrelevant :D. Can you guide me how to make a busy icon that pops up when some task is performed. – Muhammad Ali Oct 27 '15 at 04:35
-
If you are using a Action bar in your app, you can use inderminate Progressbar `requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)`, by using `true` and `false` you can show/hide it `setProgressBarIndeterminateVisibility(true);` – Murtaza Khursheed Hussain Oct 27 '15 at 04:37
-
I do not have actionBar, however I tweaked your code: `animation.setInterpolator(new CycleInterpolator(3));`, and then when I have to make the circle disappear I use `animation.end();`, now the problem is that it works on some devices that I tested but not on all of them. – Muhammad Ali Oct 27 '15 at 04:48
-
No no, dont do this. You can always use dialog and use progress bar which runs inderminate. Show/hide your dialog box then. Use [ProgessDialog](http://developer.android.com/reference/android/app/ProgressDialog.html) – Murtaza Khursheed Hussain Oct 27 '15 at 04:49
-
I'm working on a weather app, and I can't use a dialogBox. [Example](http://cdn.appstorm.net/android.appstorm.net/android/files/2013/06/EZ-Weather.png). This is an example of what I want to achieve. The refresh button next to 18:52 time. When the button is pressed it would spin around, when the async task completes and the weather is updated it would stop. – Muhammad Ali Oct 27 '15 at 04:56
-
ohh, got the point. you just need an image and rotate it. `new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);`. This will rotate a image on its center point and you have to write the stop mechanism. – Murtaza Khursheed Hussain Oct 27 '15 at 04:59
-
Can I use the circle shape described in your solution instead of an imageView? – Muhammad Ali Oct 27 '15 at 05:19
-
I dont think so, its not an image. I had not tried it btw. – Murtaza Khursheed Hussain Oct 27 '15 at 05:36
-
@MurtazaKhursheedHussain Hello I know it's a bit late, but the animation seems to be running forever. clearAnimation() doesn't seem to work. Could you please help me out ? Thanks – user2125722 Feb 26 '16 at 06:56
-
it should work, are you sure you are clearing animation on progressbar instance ? – Murtaza Khursheed Hussain Feb 26 '16 at 07:18
-
6Your answer looks it may working greatly.. but one picture = 1000 words.. so if you add your output as screenshot it may useful for future users - IMHO – Ranjithkumar Apr 28 '16 at 05:25
-
1
-
@MurtazaKhursheedHussain How do I start this animation from the top of the circle? As it stands, the animation starts at x = far right, y = middle, i'd like it to start at x = middle, y = top. – dantan04 Jul 09 '16 at 14:30
-
1You need to use `rotate` element before the `shape` element. – Murtaza Khursheed Hussain Jul 11 '16 at 04:49
-
-
-
All I see when I run this is a square of whatever color I set the `solid` to – Cbas Sep 02 '16 at 17:22
-
-
How do I set progress with this? Say I want to show download progress, how do I advance the circle indicator according to download percentage? – EZDsIt Oct 20 '16 at 20:37
-
@EZDsIt in xml via `android:progress="0"` or programtically via `setProgress` method – Murtaza Khursheed Hussain Oct 21 '16 at 06:06
-
This seems to work if the animation is only run once. If I add a repeatmode of Reverse or add an animation end listener and restart the animation, the circle stops at the second to last tick and doesn't complete the circle. Have you seen this behavior? – user2966445 Dec 19 '16 at 17:02
-
-
-
1Good solution. To set background change circular.xml to layer-list and add secondaryProgress item. – LaYer Sutachad Jul 19 '17 at 07:52
-
sir it works but it gives me an inaccurate animation, which is it runs fast at first at in the end it runs slowly. – Beginner Sep 25 '17 at 03:04
-
`which is it runs fast at first at in the end it runs slowly.` I have used `new DecelerateInterpolator ()` which means it runs fast at first and slows down on the ending. there are multiple accelerators. Try to use none – Murtaza Khursheed Hussain Oct 04 '17 at 12:38
-
style="@android:style/Widget.ProgressBar.Horizontal" I had to change the style to this for the ProgressBar – pnkflydgr Dec 14 '17 at 00:21
-
Remember to add **xmlns:android="http://schemas.android.com/apk/res/android"** prefix to shape xml – GotaloveCode Dec 14 '17 at 22:16
-
can you please help me with this [https://stackoverflow.com/q/48658388/5134647](https://stackoverflow.com/q/48658388/5134647) – shadygoneinsane Feb 07 '18 at 10:14
-
@MurtazaKhursheedHussain Nice answer, I'm wondering if it's any way to detect when the progressbar has finished so I can clear animation and do some stuff. – Skizo-ozᴉʞS ツ Jun 18 '18 at 09:00
-
@Skizo-ozᴉʞS yeah, you can check the progress, if its max value reached, that you can do that. – Murtaza Khursheed Hussain Jun 19 '18 at 11:12
-
But there's like a listener or something? to check everytime is moving? – Skizo-ozᴉʞS ツ Jun 19 '18 at 14:38
-
Seekbar have progress listener, Progress bar dont. so as the alternative, you have the `Timer` or `repeated post delayed handler`(https://gist.github.com/murtazakhussain/edb7be99ca74c398c44c) set to check for periodic progress. – Murtaza Khursheed Hussain Jun 20 '18 at 05:41
-
@MurtazaKhursheedHussain I did it with a listener from AnimationObject, works great. can you see this [Question](https://stackoverflow.com/questions/50942286/how-to-get-seconds-from-progressbar) please? – Skizo-ozᴉʞS ツ Jun 20 '18 at 15:37
-
Works like a charm :) Any way to add the indeterminate behavior to this and add a color to it? – Aman Alam Feb 27 '20 at 21:18
-
You can try this Circle Progress library
NB: please always use same width and height for progress views
DonutProgress:
<com.github.lzyzsd.circleprogress.DonutProgress
android:id="@+id/donut_progress"
android:layout_marginLeft="50dp"
android:layout_width="100dp"
android:layout_height="100dp"
custom:circle_progress="20"/>
CircleProgress:
<com.github.lzyzsd.circleprogress.CircleProgress
android:id="@+id/circle_progress"
android:layout_marginLeft="50dp"
android:layout_width="100dp"
android:layout_height="100dp"
custom:circle_progress="20"/>
ArcProgress:
<com.github.lzyzsd.circleprogress.ArcProgress
android:id="@+id/arc_progress"
android:background="#214193"
android:layout_marginLeft="50dp"
android:layout_width="100dp"
android:layout_height="100dp"
custom:arc_progress="55"
custom:arc_bottom_text="MEMORY"/>
-
how they are showing values in progress i m trying setProgress in on protected void onProgressUpdate() { super.onProgressUpdate(); Log.d(TAG, "onProgressUpdate"); progressBar.setProgress(progressBar.getProgress() + j); Log.d(TAG, "onProgressUpdate perc:" + j); updateMemoryAndCountValues(); } but its not working – Erum Dec 09 '14 at 11:44
-
@Top Cat how can i add animation like zoom in in circle progress or http://mikinw.blogspot.com/2013/03/glow-effect.html – user3233280 Dec 21 '14 at 08:59
-
I want to use DonutPrgress but want a gradient colour in progress and also rounded edge at one corner. How can I achieve that ? – Piyush Agarwal Jun 13 '15 at 19:46
-
Very light library here -> https://github.com/lopspower/CircularProgressBar – lopez.mikhael Oct 21 '15 at 08:22
-
1
-
how to stop this progress bar for my input percentage? – sudharsan chandrasekaran Jul 28 '16 at 11:34
-
-
Please see this question : https://stackoverflow.com/questions/44801280/drawing-a-circle-and-show-data-as-per-the-data-set – Kumar Jun 30 '17 at 16:03
-
Can you please guide how to set donut_progress in integer format as shown in image – Ashwin H Nov 14 '17 at 10:48
-
-
@RevathiManoharan you might have Gradle offline mode enabled. Try disabling it and building again. – Advait Saravade Aug 05 '18 at 17:09
-