Android-gettextsize The return value is in pixels (px), settextsize () in SP

Source: Internet
Author: User
When you use the following code, you find that the font size does not grow larger, but it becomes smaller:
size = (int) mtext.gettextsize () + 1;
Mtext.settextsize (size);
It was later found that the GetTextSize return value is in pixels (px), and Settextsize () is in SP, which results from inconsistent units.


Here you can use a different form of settextsize () to specify the unit:
settextsize (int unit, int size)
TypedValue.COMPLEX_UNIT_PX:Pixels
TypedValue.COMPLEX_UNIT_SP:Scaled Pixels
TypedValue.COMPLEX_UNIT_DIP:Device Independent Pixels


The following is normal:
size = (int) mtext.gettextsize () + 1;
Mtext.settextsize (typedvalue.complex_unit_px, size);
Source: http://blog.csdn.net/lizhenmingdirk/article/details/7349386

From for notes (Wiz)

Android-gettextsize The return value is in pixels (px), settextsize () in SP

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.