Skip to content

Instantly share code, notes, and snippets.

@tylerchesley
Created March 3, 2014 21:25
Show Gist options
  • Save tylerchesley/9334946 to your computer and use it in GitHub Desktop.
Save tylerchesley/9334946 to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment