cette fonction a fonctionné pour moi.
private void drawDigit(Canvas canvas, int textSize, float cX, float cY, int color, String text) {
Paint tempTextPaint = new Paint();
tempTextPaint.setAntiAlias(true);
tempTextPaint.setStyle(Paint.Style.FILL);
tempTextPaint.setColor(color);
tempTextPaint.setTextSize(textSize);
float textWidth = tempTextPaint.measureText(text);
//if cX and cY are the origin coordinates of the your rectangle
//cX-(textWidth/2) = The x-coordinate of the origin of the text being drawn
//cY+(textSize/2) = The y-coordinate of the origin of the text being drawn
canvas.drawText(text, cX-(textWidth/2), cY+(textSize/2), tempTextPaint);
}
Vérifiez cela, il est un peu ce même que ce dont vous avez besoin, http://stackoverflow.com/questions/13285510/how-to-overlay-image-with- multiline-texttext-will-être-dans-le-centre-de-la-toile/13287621 # 13287621 – Atrix1987
Essayez ceci, c'est du travail pour moi: http://stackoverflow.com/questions/11120392/android-center-text-on- toile –
Ce travail pour moi, essayez-le. [http://stackoverflow.com/questions/11120392/android-center-text-on-canvas](http://stackoverflow.com/questions/11120392/android-center-text-on-canvas) –