Android ApiDemos example resolution (68): Graphics-& gt; MeasureText

Source: Internet
Author: User

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
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.