Why should we use sp for font sizes in Android?

AndroidUser Interface

Android Problem Overview


> Possible Duplicate:
> Difference of px, dp, dip and sp in android

I am new to Android and I was trying out this tutorial

In that tutorial, they used the unit "sp" for textSize attribute and "dp" for other attributes.

Please tell me how sp differs from dp?

Android Solutions


Solution 1 - Android

The dp has constant ratio transition to px: dp = px * ratio. Where ratio will never change on any particular device.

While sp (s for scaled) has scalable ratio: sp = px * ratio * scale. Where ratio never changes, but scale is user configurable. This scale can be used by people who need larger font sizes, for example, to use device more comfortably.

Solution 2 - Android

Sp is scaled independently with respect to the normal font size of the device. http://developer.android.com/guide/practices/screens_support.html

> Similarly, you should prefer the sp (scale-independent pixel) to define text sizes. The sp scale factor depends on a user setting and the system scales the size the same as it does for dp.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVigneshwaranView Question on Stackoverflow
Solution 1 - AndroidinazarukView Answer on Stackoverflow
Solution 2 - AndroidDavid OlssonView Answer on Stackoverflow