[Android] paint font, width, and other attributes in Android

Source: Internet
Author: User

The typeface class is used in the android SDK to define the font. You can set the font type by using the common font type name, such as setting the default:

Paint MP = NewPaint ();

MP. settypeface (typeface. default_bold)



Common Font types include:

* Typeface. Default // Regular font type

* Typeface. default_bold // specifies the font type of the bold font.

* Typeface. monospace // same width font type

* Typeface. sans_serif // sans serif font type

* Typeface. serif // serif font type

In addition to font type settings, you can also set the font style for the font type, such as bold:

Paint MP = NewPaint ();

Typeface font = typeface. Create (typeface. sans_serif, typeface. Bold );

P. settypeface (font );



Common font style names include:

* Typeface. Bold // bold

* Typeface. bold_italic // bold italic

* Typeface. italic // Italic

* Typeface. Normal // General



But sometimes the above settings do not work in the drawing process, so there are the following settings:

Paint MP = NewPaint ();

MP. setfakeboldtext ( True); // True indicates bold, and false indicates non-bold.

MP. settextskewx (-0.5f); // float type parameter. A negative value indicates the Right oblique and an integer indicates the left oblique.

MP. setunderlinetext ( True); // True indicates the underline, and false indicates the non-underline.

MP. setstrikethrutext ( True); // True indicates strikethrough, and false indicates non-strikethrough.



Commonly used methods of painting include:

MP. settextsize (); // set the font size, int type, such as 12

MP. setstrokewidth (w); // set the line width and float type, such as 2.5f. You do not need to set the default value for text painting (the default value seems to be 0), but if it is set, when drawing the text again, it must be restored to 0.


Note: For bold Chinese settings, it seems that you can only use setfakeboldtext (true), although the effect does not look very real (font hollow effect ). The actual results are also related to the mobile phone hardware, such as the preceding drawing test program.


From: http://happyin1111.blog.163.com/blog/static/164184801201171911364435/


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.