Progress bar

Is there a way to make the progress bar in the shape of a circle? I have a play button in my applications and would like to show the progress of the song loading around the button.

+2


a source to share


1 answer


The ProgressBar widget has two modes that affect how it looks:

  • In progress mode, you get a straight line in which you can set the value of the progress while passing
  • In undefined mode, you get a circular animation that rotates until you stop it.

I recently built a countdown progress bar where I wanted the drawer to "spin" like a clock going backwards as time ticked down. This is very similar to what you want to do, just the opposite.

What I did was create my own class that subclasses View. Then, in my onDraw () override, I painted directly onto the canvas. It may seem overly complicated, but it is very easy and in fact to control the entire drawing process.



Something like this to draw a box all the way ...

@Override
public void onDraw(Canvas canvas) {
    Rect rect = canvas.getClipBounds();
    rect.inset(10f, 10f);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Join.ROUND);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(10f);
    canvas.drawRect(countdownRect, paint);
}

      

... there are many drawing methods that you can use to draw other shapes, lines, paths, circles, etc.

0


a source







All Articles