[Android] The font uses the dp unit to avoid the effect of setting the system font size on the layout.

Source: Internet
Author: User

[Android] The font uses the dp unit to avoid the effect of setting the system font size on the layout.

Take mx3 as an example. You can select the font size from Settings> display> font size, for example:


Figure 1. mx3

This may cause the "associated" display of the software to be incomplete on a fixed page. For example.


Figure 2. Incomplete font display

To solve this problem, change the unit of font size in TextView from sp to dp.

This example shows that the height of the content cannot be fully displayed due to the font size setting. Another case is that because the font size increases, only one line of content can be displayed, and the current behavior is two lines. This may also damage the original design aesthetic. Therefore, for a page with strict typographical requirements, use the dp unit for its font size.

Appendix:

Figure 1 sets "default", "medium", and "large", which affects fontScale under Configuration.

Run the following code to obtain the result:

Configurationconf = getResources (). getConfiguration (); LogOut. e ("fontScale =" + conf. fontScale );

Print result:

Lab. sodino. network. mainActivity-> fontScale = 1.12 // large lab. sodino. network. mainActivity-> fontScale = 1.06 // medium lab. sodino. network. mainActivity-> fontScale = 1.0 // default

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.