4

Possible Duplicate:
Difference of px, dp, dip and sp in Android?

So I know I should use sp only for text font sizes. Now, what I don't understand is what they do exactly. Let's say I have the following attribute for a TextView in a layout for a normal screen size:

android:textSize="17dp"

If I replace it with this:

android:textSize="17sp"

What happens? In the visual editor, it doesn't look any different?

I am guessing that if I have, say a 3.2" screen which qualifies for the normal size layout, and a 4.0" screen which also qualifies for my normal size layout, then if I use sp, the text's size will be slightly scaled up? Is that right?

Community
  • 1
  • 1
capcom
  • 3,257
  • 12
  • 40
  • 50
  • just read this: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension – hovanessyan Aug 18 '12 at 16:14
  • @hovanessyan Already did, still unsure. Thanks. – capcom Aug 18 '12 at 16:15
  • well according to the document, sp is the same as dp, but it also takes user preferences into account. So it makes sense to use SP for font size and DP for everything else... – hovanessyan Aug 18 '12 at 16:18
  • 1
    In a 4.x emulator or device, go into Settings > Display > Font size, and change it from "normal" to something else. – CommonsWare Aug 18 '12 at 16:22
  • @hovanessyan But then if they do want a larger font, won't that throw off my layout if the font size increases? – capcom Aug 18 '12 at 16:42

2 Answers2

3

text rendered with sp is more compatible with accessibility options, for example if the users enables a high contrast mode or universally increases the size of text. Since sp is also density independent, that is the only difference between sp and dp.

Xavier
  • 3,423
  • 23
  • 36
0

I wouldn't like to start a new thread about it is so please have a look on a thread where it was already answered. Your question is answered mostly in the comments. Difference of px, dp, dip and sp in Android?

Community
  • 1
  • 1
Martin Rajniak
  • 630
  • 8
  • 26