I'm looking for a smooth way to implement a "state" progressbar in Android like shown in the three examples below. As I'm not a fan of reinventing the wheel I'd like to ask if there is some library available I don't know about.
I looked it up and couldn't find any lib so I guess I need to implement it by myself. What would be the easiest solution to do so? Should I extend ProgressBar or should I do it from scratch? Do you have any suggestions or tutorials I could build up on?
The
ProgressBar
widget delegates the drawing of it's progress to it's assigned progressDrawable
by setting the appropriate level on it. The default* progressDrawable
is alayer-list
** that contains three layers: background, progress, and secondary progress. The last two are wrapped inclip
orscale
containers that are automatically clipped or scaled to their percentage based on their levels. They are also assigned special ids thatProgressBar
searches for and handles specifically instead of the wholeDrawable
if theDrawable
happens to be alayer-list
.In your case, since the progress increments aren't all equal, you can use a
level-list
drawable container as your progress layer, and provide assets for all your progress increments to it. Alternatively, if you wish to make it dynamic, you can create a customDrawable
subclass with the appropriate drawing logic based on it's level.Here is a sample XML for the progress
Drawable
resource using alevel-list
:* You can find the original non-Holo version here, and the Holo versions here and here.
** You can find a list of the standard framework
Drawable
s that can be defined in XML here.Update
Please see the this sample project, Also GIF is attached to give overview.
You can customize the following to your requirement.
Link 1
Link 2
Link 3
Link 4
Link 5
Link 6
You can also do it with linear layout. I have done a simple example, just a simple example.
MainActivity.java