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?
dp has constant ratio transition to
dp = px * ratio. Where
ratio will never change on any particular device.
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.
Sp is scaled independently with respect to the normal font size of the device.
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.