Why is it recommended to use "sp" instead of "dp" in text sizes?

Asked

Viewed 605 times

6

Bearing in mind that when we use the unit sp in the TextView there’s always a Warning in this way:

Should use "sp" Instead of "dp" for text Sizes

In this Sopt response shows exactly the difference between the units of measure: Doubt about px, dp, Dip and sp on Android?

sp

Scale-Independent Pixels - Idem to dp, but also consider the size the source the user is using. It is recommended to use this unit when specifying the size of a font, so that it is automatically adjusted to user screen preferences.

dip ou dp

Density-Independent Pixels - This unit shall relate to the resolution of screen. For example if the screen resolution is 160 dpi, it means that a dp represents 1 pixel in a total of 160. USE: I advise instead px always use dp.

The issue of recommendation is in relation to the size that the user defines his source in ACCESSIBILITY in the device settings? Why the recommendation? Why is it recommended to use "sp" instead of "dp" in text sizes?

  • I don’t understand what your question is.

  • @ramaral The question is: Why it is recommended to use "sp" instead of "dp" in text sizes?

1 answer

5


The recommendation is based on the assumption that the user when he changes the text size in the accessibility definitions expects it to be reflected in all texts of all applications.

For this to happen the font size of the texts will have to be set with the unit sp.

The text size will not only adjust to the pixel density of the screen but also take into account the setting chosen in the Accessibility options.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.