This is probably best done using a custom view . To establish progress, you must define the setter as shown below, which invalidates the view and calls onDraw ().
public class CustomProgressBar extends View {
The next step is to draw a part of the view that indicates progress, and a part that indicates the remaining work.
final Paint progressPaint = new Paint(); progressPaint.setColor(Color.RED); // could draw a bitmap or whatever, this is a simple example @Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); // clear previous contents float progressW = getWidth() * (progress / 100); float remainingW = getWidth() - progressPortion; canvas.drawRect(0, 0, progressW, getHeight(), progressPaint); canvas.drawRect(progressW, 0, remainingW, getHeight(), remainingPaint); }
Finally, you can calculate the positions of your circle indicators, inside onDraw () draw them on the canvas.
final float radius = 5; final float circleCount = 6; float unit = getWidth() / circleCount; float offset = 0; for (int i=0; i<6; i++) { canvas.drawCircle(offset + (radius / 2), getHeight() / 2, radius, circlePaint); }
If you need to conditionally display indicators, you can simply add a check during the onDraw () method to see if progress has passed a certain threshold.
source share