Created
October 9, 2018 02:21
-
-
Save namchuai/92adbad54ecf2b638d126d44681f20f9 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
| public static int getApproxXToCenterText(String text, Typeface typeface, int fontSize, int widthToFitStringInto) { | |
| Paint p = new Paint(); | |
| p.setTypeface(typeface); | |
| p.setTextSize(fontSize); | |
| float textWidth = p.measureText(text); | |
| int xOffset = (int)((widthToFitStringInto-textWidth)/2f) - (int)(fontSize/2f); | |
| return xOffset; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment