Friday, 6 December 2013

Create a Circular Progress Bar in Android

For my current project, BreakFree, I needed a circular Progress bar, and not the spinning kind. A progress bar that behaves like the horizontal one, but is circular. 

A circular one would fit my layout a lot better. I did not find a straight answer on the internet  but I did manage to put one together, so I thought I'd write a TUT for it. In case anyone decides on creating such a Progress Bar.

This is what the final result should look like (Ignore the number in the center):

Lets start with the steps to recreate this view.

1) You will need to create a drawable which defines your progress bar. Here you will give it the shape of a ring. Adjust the inner radius and thickness of the ring as you wish. I have also added a gradient starting from red, moving to yellow and then ending in green. You can play around with these settings.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="" >
<item android:id="@android:id/progress">
             android:type="sweep" />   

2) In your layout xml, create a horizontal Progress bar. And set the progressDrawable to the drawable file created in step 1 (in my case I have named the file in step 1 circular_progress_bar.xml.

        android:progressDrawable="@drawable/circular_progress_bar" />

3) Most of our job is done. Now the only problem is that since this is a horizontal progress bar, it is aligned horizontally and not vertically. So basically the start and finish is to the right of the circle and not at the bottom. To counter this I used RotationAnimation to rotate the Progress Bar by 90 degrees. This will rotate the progress bar and the start and finish will be at the bottom of the circle making it look realistic. Since I have not specified a duration the animation will happen as soon as the view is created.

ProgressBar pb = (ProgressBar) view.findViewById(;

Animation an = new RotateAnimation(0.0f, 90.0f, 250f, 273f);

I hope this helps.

Until next time.

EDIT: Lollipop onwards Android has changed the default value for useLevel from "true" to "false". Hence you now need to add android:useLevel="true" in the shape tag in the drawable.

No comments:

Post a Comment