android – What is the difference between px, dp, dip and sp?

Question:

What is the difference between px , dp , dip and sp on Android?

Answer:

  • px :

DEFINITION: Corresponding to the number of pixels on the screen USAGE: avoid using px for everything, it is recommended only in very specific cases.

  • sp :

DEFINITION: (Scale-independent Pixels) Same as dp, but also considers the font size the user is using. It is recommended that you use this unit when specifying a font size so that it is automatically adjusted to the user's screen preferences. USE: Always use sp for fonts!

  • dip or dp :

DEFINITION: (Density-independent Pixels) This unit is relative to the screen resolution. For example if the screen resolution is 160 dpi, it means that a dp represents 1 pixel out of a total of 160. USAGE: I advise instead of using px always use dp.


We still have other measurement units used by Android

  • in : (inches)

DEFINITION: Based on physical screen size

  • mm : (millimeter)

DEFINITION: Based on physical screen size

  • en : (points)

DEFINITION: 1/72 of an inch, based on physical screen size

More about measurement units and dimensions on Android here A super explanatory video created by @NetoMarin http://www.youtube.com/watch?v=Ocaq1bu3f2w

Scroll to Top