Draw text inside android circle -


public static bitmap drawcircle(int width,int height, int borderwidth) {     bitmap canvasbitmap = bitmap.createbitmap( 350, 350, bitmap.config.argb_8888);     bitmapshader shader = new bitmapshader(canvasbitmap, tilemode.clamp, tilemode.clamp);     paint paint = new paint();     paint.setantialias(true);     paint.setshader(shader);     paint.setshader(null);     paint.setstyle(paint.style.stroke);     paint.setcolor(color.white);     paint.setstrokewidth(borderwidth);      paint paint1 = new paint();     paint1.setantialias(true);     paint1.setshader(shader);     paint1.setshader(null);     paint1.setstyle(paint.style.stroke);     paint1.setcolor(color.white);     paint1.setstrokewidth(borderwidth);      canvas canvas = new canvas(canvasbitmap);     float radius = width > height ? ((float) height) / 2f : ((float) width) / 2f;     //canvas.drawcircle(width / 2, height / 2, radius - borderwidth / 2, paint);     final rectf rect = new rectf();     rect.set(100, 100, 300, 300);      canvas.drawarc(rect, 270, 90, false, paint1);     canvas.drawtext("25%", 100, 100, 100, 100, paint1);     return canvasbitmap; } 

how can draw text inside arc? indexoutofboundexception in drawtext... parameter shall pass? how can inside arc?

you try this.

    private paint paint;     private paint circlepaint;      paint = new paint();     circlepaint = new paint();      paint.setcolor(color.white);     paint.settextsize(18f);     paint.setantialias(true);     paint.settextalign(paint.align.center);      rect bounds = new rect();     paint.gettextbounds(text, 0, text.length(), bounds);      circlepaint.setcolor(color.red);     circlepaint.setantialias(true);      canvas.drawcircle(-3, 15 - (bounds.height() / 2), bounds.width() + 5, circlepaint);      canvas.drawtext(text, -3, 15, paint); 

note : (-3,15) starting co-ordinates draw text , (+5) padding.

this should give output notification badge here -> sample


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -