Android 4.2 on Nexus 7: canvas.drawText() not working correctly

I answer my own question after a lot of googling… The trick consist in the use of setLinearText(true) for the Paint object used for drawing the text. Now, everything looks great. paint = new Paint(); paint.setAntiAlias(true); paint.setColor(color); paint.setTextSize(size); paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); paint.setTextAlign(Align.CENTER); paint.setLinearText(true); Here the link that saves my day: http://gc.codehum.com/p/android/issues/detail?id=39755 I hope it can help someonelse. … Read more

Android Canvas.drawText

Worked this out, turns out that android.R.color.black is not the same as Color.BLACK. Changed the code to: Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setStyle(Style.FILL); canvas.drawPaint(paint); paint.setColor(Color.BLACK); paint.setTextSize(20); canvas.drawText(“Some Text”, 10, 25, paint); and it all works fine now!!

Android Center text on canvas

Try the following: Paint textPaint = new Paint(); textPaint.setTextAlign(Paint.Align.CENTER); int xPos = (canvas.getWidth() / 2); int yPos = (int) ((canvas.getHeight() / 2) – ((textPaint.descent() + textPaint.ascent()) / 2)) ; //((textPaint.descent() + textPaint.ascent()) / 2) is the distance from the baseline to the center. canvas.drawText(“Hello”, xPos, yPos, textPaint);