Skip to content

Instantly share code, notes, and snippets.

@brucetoo
Created March 24, 2016 12:39
Show Gist options
  • Save brucetoo/3e7a77dce3029afda72a to your computer and use it in GitHub Desktop.
Save brucetoo/3e7a77dce3029afda72a to your computer and use it in GitHub Desktop.
绘制居中字体
Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
float textWidth = mTextPaint.measureText(mText);
float textCenterVerticalBaselineY = mButton.getHeight() / 2 - fontMetrics.descent + (fontMetrics.bottom - fontMetrics.top) / 2;
canvas.drawText(mText,mButton.getWidth() / 2 - textWidth / 2,textCenterVerticalBaselineY,mTextPaint);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment