Skip to content

Instantly share code, notes, and snippets.

@yuanliwei
Created March 11, 2016 09:16
Show Gist options
  • Save yuanliwei/c153421d6562709ca9de to your computer and use it in GitHub Desktop.
Save yuanliwei/c153421d6562709ca9de to your computer and use it in GitHub Desktop.
Android drawText 文字垂直居中
float textWidth = paintOval.measureText(progressText);
Paint.FontMetricsInt fmi = paintOval.getFontMetricsInt();
float left = (width - textWidth) / 2;
float top = (height - fmi.bottom - fmi.top) / 2;
canvas.drawText(progressText, left, top, paintOval);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment