How to Create a circular progressbar in Android which rotates on it?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When an Android screen is waiting on network or background work, a rotating circular indicator is the standard visual cue. The shortest path is to use an indeterminate ProgressBar, but custom styling is often needed to match the app design. The key is to decide whether the built-in widget is enough or whether you need a custom drawable and animation.
Start with the Built-In Indeterminate ProgressBar
If you just need a rotating loader, Android already provides it. In XML:
In an Activity:
This is enough for many apps. Do not build a custom spinner just to reproduce the default one.
Create a Custom Circular Drawable
If you want your own color, stroke width, or visual style, create a ring drawable in res/drawable/circular_loader.xml:
This gives you a circular ring that can be rotated. On its own, it is just a static drawable, so you still need animation.
Apply a Rotation Animation
Create res/anim/rotate_clockwise.xml:
Then attach it to an ImageView or other view that uses the circular drawable:
Kotlin code:
That gives you a custom rotating circular progress indicator.
Show and Hide It with Real Work
The spinner should reflect actual background state. For example:
The exact background work will differ, but the principle is the same: show the loader before work starts and hide it on completion or failure.
If you are on Material Components, also consider CircularProgressIndicator, which provides a modern default with less custom code.
Pick the Simplest UI Layer for Your App
If the screen already uses classic Views, the XML and ProgressBar approach above is the lowest-friction option. If the app is on Jetpack Compose, use the framework-provided indicator instead of trying to port old animation resources.
The principle stays the same across UI toolkits: prefer the platform default unless you have a strong design requirement that justifies a custom loader.
Common Pitfalls
- Rebuilding a custom loader when the built-in indeterminate
ProgressBarwould already solve the problem. - Using a non-linear interpolator, which makes the rotation feel jerky instead of steady.
- Forgetting to stop or hide the animation when the background work ends.
- Styling a static ring drawable without attaching an actual rotation animation.
- Running long work on the main thread so the spinner freezes instead of animating smoothly.
Summary
- Use an indeterminate
ProgressBarfirst if the default look is acceptable. - For custom visuals, create a circular drawable and rotate it with an animation resource.
- Keep the animation linear so the motion feels continuous.
- Tie spinner visibility to real async work rather than leaving it on screen permanently.
- Prefer simple built-in widgets unless the app genuinely needs a branded loader.
Related reading
- How to create a colored 1x1 UIImage on the iPhone dynamically?
- How to create a Custom Dialog box in android?
- How to create a delay in Swift?
- How to create a delay in Swift?
- How to create a DialogFragment without title?
- How to create a GUID/UUID using iOS
- How to create a Looper thread, then send it a message immediately?
- How to create a multiline UITextfield?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.