Android development experience gets the length and width of the string drawn on the canvas (the pixel width)

Source: Internet
Author: User

  1. Get string length, Width (pixel width) in Android
  2. Calculate how wide the currently drawn string is, so come on!
  3. Method 1:
  4. Paint paint = new paint ();
  5. Rect rect = new rect ();
  6. Returns the smallest RECT area enclosing the entire string
  7. Paint.gettextbounds (text, 0, 1, rect);
  8. Strwid = Rect.width ();
  9. Strhei = Rect.height ();
  10. Method 2:
  11. Directly returns the width occupied by the argument string
  12. Strwidth = Painthead.measuretext (text);

Android development experience gets the length and width of the string drawn on the canvas (the pixel width)

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.