About units in Android (DP, SP)

Source: Internet
Author: User

Android is a headache adaptation problem.

---------

The units in Android probably have these:



Dip, SP, often used. Sometimes the PX is used.

---------

Two classes are introduced:

Typedvalue: There are some units that convert related methods.

Displaymetrics:

Displaymetrics dm = new Displaymetrics (); Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
Displaymetrics have these units to convert related fields:


---------

Their relationship:

Dip = displaymetrics.density * px

= (densitydpi/160) * px

SP and dip are the same. Only the SP will vary depending on the device and is also affected by user settings (the general path is in: Settings-appearance-font size). And, to be indignant, on the Sony Xperia C3 (do not know whether all Xperia is so), the system default font size display is "normal", the actual display effect and other equivalent machines in the "big" font is the same. This means that some systems have default font size settings that are inconsistent with the Android native system.

So how do you control the effect of the display?

---------

Do you want to use dip, sp? Dip to use. Solve the adaptation problem to a great extent. SP to use? My advice is not to.

It depends on you. Suppose your app is intended for people who have bad eyes (for example, hard-working elders), and you can specify a super-large font directly. If you do not consider vision, for the sake of beauty, do not let the user change the font size. Assume that the two types of people are covered. Just use SP (not necessarily ~).



About units in Android (DP, SP)

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.