While defining a view in android, we use dp for margins, sizes, etc but for text sizes we use sp. sp is also same as dp but for texts. Why can't we use sp for everything then? I know the difference in between the two. I am asking if sp is a superset of dp, why use dp at all? why not use sp to specifiy all sizes in views?
Asked
Active
Viewed 1,642 times
2
-
5Possible duplicate http://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dp-dip-and-sp-on-android. – Sagar Gangawane Nov 21 '16 at 09:36
-
see my answer http://stackoverflow.com/a/40717863/6893465 see the difference on different screen size.. – cpt. Sparrow Nov 21 '16 at 10:26
2 Answers
4
The reason we can't use sp for everything is that when we increase the font size from settings,we only want the text to resize and not the buttons and other views as well. So we use dp for the rest and just sp for the text.

Rishikesh Shukla
- 317
- 1
- 12
2
The sp unit of measurement is used for fonts and is pixel density dependent in the exact same way that dp is. The extra calculation that an Android device will take into account when deciding how big your font will be, based on the value of sp you use, is the user's own font size settings. So, if you test your app on devices and emulators with normal size fonts, then a user who has a sight impairment (or just likes big fonts) and has the font setting on large, will see something different to what you saw during testing.

Kostasfra
- 165
- 1
- 9