1. dip: Device Independent pixels (device independent pixel ). different devices have different display effects. This is related to the hardware of the device. We recommend that you use this function to support WVGA, hvga, and qvga without pixels.
Note that the dip is related to the screen density, and the screen density is related to the specific hardware. Incorrect hardware settings may cause the dip to fail to be properly displayed. On a display with a screen density of 160, 1dip = 1px, sometimes your screen resolution may be large, such as 480*800, but the screen density is not properly set, for example, 160, when dip is used, an exception is displayed, which is usually too small.
Dip conversion:
Dip (value) = ( Int ) (PX (value)/1.5 + 0.5)
2. DP: Very simple. It is the same as dip.
3. Px: pixels (pixels). Different devices have the same display effect on different display screens. This is an absolute pixel, and the value will never change.
4. SP: scaled pixels (zoom in pixels). It is mainly used for displaying the best font. For Textsize.
Note: according to Google's recommendation, dip is used for pixels and SP is used for fonts.
For example, the difference between PX and dip is as follows:
PX is a pixel. If PX is used, it will be drawn using the actual pixel. For example, draw a horizontal line with a length of PX, in a 480-width simulator, the screen width is half the screen width, and in a 320-width simulator, the screen width is 2/3.
DIP is to divide the screen's high score into 480 points and the width into 320 points. For example, if you build a 320 dip horizontal line, whether you are on a 480 or simulator, it is half the screen length.
Public Static Int Dip2px (context, Float Dipvalue ){
Final Float Scale = context. getresources (). getdisplaymetrics (). density;
Return ( Int ) (Dipvalue * scale + 0.5f );
}
Public Static Int Px2dip (context, Float Pxvalue ){
Final Float Scale = context. getresources (). getdisplaymetrics (). density;
Return ( Int ) (Pxvalue/scale + 0.5f );
}