Canvas provides drawText and drawPostText to display text on the screen. The font type and size are defined by setting the paint attribute.
Painting also provides the size (width, height, range, etc.) occupied by the text on the screen when the text string is drawn using the current font and size ).
MeasureText describes how to use the method provided by Paint to measure the text size.
[Java]
MPaint. setTextSize (64 );
MPaint. setTypeface (Typeface. create (Typeface. SERIF,
Typeface. ITALIC ));
...
Int count = mPaint. getTextWidths (text, 0, text. length (), widths );
Float w = mPaint. measureText (text, 0, text. length ());
MPaint. getTextBounds (text, 0, text. length (), bounds );
MPaint. setTextSize (64 );
MPaint. setTypeface (Typeface. create (Typeface. SERIF,
Typeface. ITALIC ));
...
Int count = mPaint. getTextWidths (text, 0, text. length (), widths );
Float w = mPaint. measureText (text, 0, text. length ());
MPaint. getTextBounds (text, 0, text. length (), bounds); the final size of the text is related to the font type of the text to be drawn and the font size, the font type and size are both set by the Paint object setTypeface and setTextSize.
GetTextWidths provides the widths array to return the width of each character in the text string drawn using the current font. While measureText returns the width of the entire string. GetTextBounds indicates the size of the rectangle occupied by the returned string.
Author: mapdigit