Skip to content

Instantly share code, notes, and snippets.

@piyush-malaviya
Created September 5, 2021 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piyush-malaviya/1616d056b5f71b14267acd110e5a0a3f to your computer and use it in GitHub Desktop.
Save piyush-malaviya/1616d056b5f71b14267acd110e5a0a3f 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);
https://stackoverflow.com/a/38415380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment