public static Bitmap drawCircle(int width,int height, int borderWidth) {
Bitmap canvasBitmap = Bitmap.createBitmap( 350, 350, Bitmap.Config.ARGB_8888);
BitmapSha
I had a similar requirement where needed text drawn in the centre of a circle.
Here's how I did it (within my customview's onDraw
) albeit it similar to @Anoop's answer.
//draw circle
canvas.drawCircle(xPos,yPos,mCircleSize, mCirclePaint);
mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
//this ensures X alignment
mTextPaint.setTextAlign(Paint.Align.CENTER);
// Measure the text rectangle to get the height
Rect result = new Rect();
mTextPaint.getTextBounds(marker.label, 0, marker.label.length(), result);
//take half the height as the offset
int yOffset = result.height()/2;
//add offset to ensure Y is aligned center
canvas.drawText(marker.label, xPos, yPos+yOffset, mTextPaint);