Home android What's the difference between px, dp, dip and sp on Android?

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

Author

Date

Category

What is the difference between these units of measurement on Android?

  • px
  • dip
  • dp
  • sp

Answer 1, authority 100%

According to documentation :

  1. px
    Pixel – corresponds to one pixel on the screen. It is not recommended to use, as the elements will look different on different devices (the physical size of one pixel is different on each device).

  2. in
    Inch – corresponds to the actual physical size of the elements on the screen (1 inch ≈ 2.54 & nbsp; cm)

  3. mm
    Millimeter – also corresponds to the real size (1 mm = 0.01 & nbsp; cm)

  4. pt
    Dot – 1/72 inch, real size (1 dot ≈ & nbsp; 3.5 mm)

  5. dp or dip
    Density-independent Pixel is a relative unit of measurement based on the density of a device’s screen. Corresponds to about one pixel on a 160 dots per inch (dpi) device. The dp / px ratio changes according to the screen density, but not in strict proportion: dp / dx depends on the screen category, not the exact density value. It is recommended to use px instead of usual for correct display of elements on devices with different screen densities. You can write both dip and dp in markup, the compiler treats both options the same, but dp is preferred.

  6. sp
    Scale-independent Pixel – a pixel independent of scaling – like dp, it depends on the screen density, but the result will be scaled according to the user’s font size settings. Recommended for setting font sizes so that the text adapts to both screen density and user-defined settings

From Understanding Density Independence In Android :

+ --------- + -------------- + --------------- + ------------ + ------------- +
| Unit | Name | In 1 inch | Depends on | Identical |
| | | | density? | physical size |
+ --------- + -------------- + --------------- + -------- ---- + ------------- +
| px | Pixel | - | Yes | No |
+ --------- + -------------- + --------------- + -------- ---- + ------------- +
| in | Inch | 1 | No | Yes |
+ --------- + -------------- + --------------- + -------- ---- + ------------- +
| mm | Millimeter | 25.4 | No | Yes |
+ --------- + -------------- + --------------- + -------- ---- + ------------- +
| pt | Point | 72 | No | Yes |
+ --------- + -------------- + --------------- + -------- ---- + ------------- +
| dp | Pixel, | ~ 160 | No | No |
| | independent | | | |
| | on the density | | | |
+ --------- + -------------- + --------------- + -------- ---- + ------------- +
| sp | Pixel, | ~ 160 | No | No |
| | independent | | | |
| | from the scale- | | | |
| | rationing | | | |
+ --------- + -------------- + --------------- + -------- ---- + ------------- +

Visual: Google Design Documentation .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions