Created
March 24, 2016 12:39
-
-
Save brucetoo/3e7a77dce3029afda72a to your computer and use it in GitHub Desktop.
绘制居中字体
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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