Domanda

What would be the best way to make this circle in android? I don't want to learn OpenGL just to draw a simple progress circle (ring), but if there's no other way I will. Before start, I want to ask you guys, what do you think. I'm open to all kind of suggestions on how to make this.

An embossed circle, blue over half way around, showing \"69%\" in the middle.

È stato utile?

Soluzione

There is a ProgressBar widget built into Android, that by default renders as a circle.

You can use an ImageView backed by a ShapeDrawable that is a ring, with a gradient sweep fill of your choosing.

You can create 100 PNG files, one per percentage, and use those, perhaps via a LevelListDrawable.

You can draw the whole thing yourself as a custom View using the Canvas.

There are probably other alternatives as well, but this should get you going.

Altri suggerimenti

Apparently not too hard using SVG, check out Leandro Linares' progress circle example

Tanks to @CommonsWare, here it is my code example

public class SampleView extends View {

    public SampleView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Canvas canvas.drawColor(Color.CYAN);
        Paint p = new Paint();
        // smooths
        p.setAntiAlias(true);
        p.setColor(Color.RED);
        p.setStyle(Paint.Style.STROKE); 
        p.setStrokeWidth(5);
        // opacity
        //p.setAlpha(0x80); //

        RectF rectF = new RectF(50, 20, 100, 80);
        canvas.drawOval(rectF, p);
        p.setColor(Color.BLACK);
        canvas.drawArc (rectF, 90, 45, true, p);
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top