Difference Between Px, Dip, Dp, and Sp

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

From the Android Developer Documentation:


  1. px

    Pixels - corresponds to actual pixels on the screen.


  2. in

    Inches - based on the physical size of the screen.

    1 Inch OR 2.54 centimeters


  3. mm

    > Millimeters - based on the physical size of the screen.


  4. pt

    > Points - 1/72 of an inch based on the physical size of the screen.


  5. dp or dip

    > Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160
    dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".


  6. sp

    > Scaleable Pixels OR scale-independent pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommended you
    use this unit when specifying font sizes, so they will be adjusted
    for both the screen density and the user's preference. Note, the Android documentation is inconsistent on what sp actually stands for, one doc says "scale-independent pixels", the other says "scaleable pixels".

From Understanding Density Independence In Android:

















































Density BucketScreen DensityPhysical SizePixel Size
ldpi120 dpi0.5 x 0.5 in0.5 in * 120 dpi = 60x60 px
mdpi160 dpi0.5 x 0.5 in0.5 in * 160 dpi = 80x80 px
hdpi240 dpi0.5 x 0.5 in0.5 in * 240 dpi = 120x120 px
xhdpi320 dpi0.5 x 0.5 in0.5 in * 320 dpi = 160x160 px
xxhdpi480 dpi0.5 x 0.5 in0.5 in * 480 dpi = 240x240 px
xxxhdpi640 dpi0.5 x 0.5 in0.5 in * 640 dpi = 320x320 px

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

From the Android Developer Documentation:


  1. px

    Pixels - corresponds to actual pixels on the screen.


  2. in

    Inches - based on the physical size of the screen.

    1 Inch OR 2.54 centimeters


  3. mm

    > Millimeters - based on the physical size of the screen.


  4. pt

    > Points - 1/72 of an inch based on the physical size of the screen.


  5. dp or dip

    > Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160
    dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".


  6. sp

    > Scaleable Pixels OR scale-independent pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommended you
    use this unit when specifying font sizes, so they will be adjusted
    for both the screen density and the user's preference. Note, the Android documentation is inconsistent on what sp actually stands for, one doc says "scale-independent pixels", the other says "scaleable pixels".

From Understanding Density Independence In Android:

















































Density BucketScreen DensityPhysical SizePixel Size
ldpi120 dpi0.5 x 0.5 in0.5 in * 120 dpi = 60x60 px
mdpi160 dpi0.5 x 0.5 in0.5 in * 160 dpi = 80x80 px
hdpi240 dpi0.5 x 0.5 in0.5 in * 240 dpi = 120x120 px
xhdpi320 dpi0.5 x 0.5 in0.5 in * 320 dpi = 160x160 px
xxhdpi480 dpi0.5 x 0.5 in0.5 in * 480 dpi = 240x240 px
xxxhdpi640 dpi0.5 x 0.5 in0.5 in * 640 dpi = 320x320 px

Difference between dp and sp (The other definitions that I have seen was still confusing me)?

DP (density-independent pixels) is 1 pixel on a 160 dpi screen.

SP (Scale-independent Pixels) - this resembles the dp unit, however it is likewise scaled by the user's text dimension setting.

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

From the Android Developer Documentation:


  1. px

    Pixels - corresponds to actual pixels on the screen.


  2. in

    Inches - based on the physical size of the screen.

    1 Inch OR 2.54 centimeters


  3. mm

    > Millimeters - based on the physical size of the screen.


  4. pt

    > Points - 1/72 of an inch based on the physical size of the screen.


  5. dp or dip

    > Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160
    dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".


  6. sp

    > Scaleable Pixels OR scale-independent pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommended you
    use this unit when specifying font sizes, so they will be adjusted
    for both the screen density and the user's preference. Note, the Android documentation is inconsistent on what sp actually stands for, one doc says "scale-independent pixels", the other says "scaleable pixels".

From Understanding Density Independence In Android:

















































Density BucketScreen DensityPhysical SizePixel Size
ldpi120 dpi0.5 x 0.5 in0.5 in * 120 dpi = 60x60 px
mdpi160 dpi0.5 x 0.5 in0.5 in * 160 dpi = 80x80 px
hdpi240 dpi0.5 x 0.5 in0.5 in * 240 dpi = 120x120 px
xhdpi320 dpi0.5 x 0.5 in0.5 in * 320 dpi = 160x160 px
xxhdpi480 dpi0.5 x 0.5 in0.5 in * 480 dpi = 240x240 px
xxxhdpi640 dpi0.5 x 0.5 in0.5 in * 640 dpi = 320x320 px

Is dp the same as dip?

Yes, they are the same. There is no difference, its just an alias.

Documentation:

The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".

Which measurement we should use in android, px, dp, dip or sp?

dip is best used for when you need something a static size. This is a "Device Independant Pixel" and will roughly be rendered the same physical size on any handset/tablet.

Ideally though, you should be using layout_weights and clever implementations of match_parent and wrap_content to fill most fields.

Edit: Just FYI, dip = dp ... compiler handles them equivocally. Use whichever you like.

When should we use dp or sp in layout?

Android recommends to use sp when you are setting font size and dp for everything else like width, length, height, margin, padding

What is the difference between dp and dip?

There's NO DIFFERENCE. dip and dp are the very same thing.



Related Topics



Leave a reply



Submit