I am trying to build a workout timer app for android sdk.

I want to learn how to build a circle and how to slowly reduce it. Take a look a image below for example. I want to get the same effect but was ever able to get it.

Any idea how can I go about this?

I am not sure how to post a image on daniweb. So please take a look at this link:

http://stackoverflow.com/questions/30316243/how-to-create-a-circle-in-android-sdk

Dani AI

Generated

: the usual, reliable pattern for a countdown ring is a small custom View that draws a ring/arc with Canvas.drawArc and reduces the arc's sweep angle from 360 to 0 as the timer runs. drawArc takes a RectF + startAngle + sweepAngle (angles in degrees, measured clockwise; 0 degrees is at 3 o'clock), and using useCenter = false produces a stroked ring instead of a pie slice. That gives full control of stroke width, colors, and where the countdown starts. (developer.android.com)

A minimal workflow: subclass View, create and configure Paint objects once (e.g., in the constructor or an init method), compute a RectF in onSizeChanged, then override onDraw to draw a background ring and a foreground arc whose sweep field you update. Example skeleton (Java):

public class CountdownView extends View {
  private Paint bg = new Paint(Paint.ANTI_ALIAS_FLAG);
  private Paint fg = new Paint(Paint.ANTI_ALIAS_FLAG);
  private RectF oval = new RectF();
  private float sweep = 360f;

  // init paints in constructor
  @Override protected void onSizeChanged(int w,int h,int ow,int oh){
    float pad = fg.getStrokeWidth()/2f;
    oval.set(pad,pad,w-pad,h-pad);
  }

  @Override protected void onDraw(Canvas c){
    c.drawArc(oval, -90f, 360f, false, bg);   // full background ring
    c.drawArc(oval, -90f, sweep, false, fg);  // remaining time arc
  }

  // call start(millis) to begin the countdown
}

Creating a view this way follows the Android custom-view pattern (override constructors, onDraw/onMeasure, use styled attributes when useful). (developer.android.com)

Animate the sweep with a ValueAnimator.ofFloat(360f, 0f), set the countdown duration, update sweep in the update listener and call invalidate() (or postInvalidateOnAnimation() for smoother frames). ValueAnimator is the recommended timing engine for this kind of UI animation. (developer.android.com)

If you want a quick drop-in instead of a custom view, the Material CircularProgressIndicator can be configured as a determinate circular timer (track/indicator thickness, colors, etc.). For production use, reuse Paint/RectF objects and avoid allocations inside onDraw to keep animations smooth (aim for stable 60fps). As pointed out, sample projects are useful to study these patterns. (developer.android.com)

I haven't been into Android for awhile but I am pretty sure will be able to help you out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.