Recently in the study of Android development, has not been clear the difference between px,dp,dip,sp. It's time to take time to study today.
As is known to all, Android manufacturers are very many, various sizes of Android phones, tablet endless. has led to a growing fragmentation of the Android ecosystem. In order to solve the problem of too much resolution, Google has defined the PX,DP,DIP,SP in the Android development document to make it easy for developers to adapt to different resolutions of Android devices.
1. Basic knowledge:
mm:millimeters mm, length unit .
In :inches inch, unit of length, screen physical size of the basic unit.
PT:points a standard unit with a size of one inch of screen size of 1/72.
dpi: dots per inch is the pixel in pixels.
As an example:
Assuming that the screen physical size of the QVGA (320*240) Resolution is (2 inches * 1.5 inches), then the phone's dpi=160.
screen size refers to the actual physical size of the phone.
If the iphone4s is 3.5 inches, this refers to the cell phone screen diagonal length is 3.5 inches.
Resolution (resolution) refers to the number of pixels in the horizontal and vertical direction of the phone screen.
Common cell Phone Resolutions: QVGA (240x320 pixels),HVGA (480x320 pixels), WVGA (800x480 pixels), 720P (1280x720 pixels), 1080P (1920x1080 pixels), 2K ( 2560x1440 pixels)
2. Basic definition:
px (Pixel's abbreviation, or pixel) refers to a pixel.
SP (scale-independent pixels) refers to the proportional independent pixels.
Dip (device independent pixels) refers to devices that are independent of pixels.
DP:(density-independent pixel) in the Android document (Http://developer.android.com/guide/practices/screens_ Support.html#terms), which is calculated by PX = DP * (dpi/160).
Take a look at what the DP unit is: pixels = DP Units * pixels per inch. You can see that the unit of DP is the unit of length in inches. Length of 1DP = 1 * dpi/160 * 1/dpi "= 1/160".
the meaning of DP is that you can set the corresponding DP value in the app according to the actual size you see, making it look as large on different devices.
3. Differences
PX (pixel) represents the real pixel of the screen, such as the current popular 1080P mobile phones and 2K mobile phones, 1080P phone is 1920x1080 pixels, that is, the phone's screen landscape has 1080 pixels, the portrait has 1920 pixels. This value is absolute , how much is how much, does not change.
SP (scale independent pixels), that is, pixels independent of density and font scaling, primarily for font size.
Dip (device independent pixels) This is the logical pixel unit, which is actually DP.
Welcome to discuss the exchange, my mailbox is [email protected].
Welcome reprint, Reproduced please specify the website, thank you!