The length of Android is: DP (or dip device independent pixels) an abstract unit based on screen density. On a monitor that is 160 dots per inch. 1dp=1px.
Different devices have different display effects. This is related to device hardware. Use unit DP;SP (scaled Pixels) when layout is used primarily for font display, a pixel independent of the scale, similar to DP. However, it is possible to scale based on the user's font size preference. PX: Indicates the actual pixel of the screen. The TextView method Settextsize uses the SP as the font size unit. The method for point Settextsize uses the PX unit. Here are the conversion and drop methods:
public static int PX2SP (context context, float Pxvalue) { final float Fontscale = context.getresources (). Getdisplayme Trics (). scaleddensity; return (int) (Pxvalue/fontscale + 0.5f); } public static int Px2dip (context context, float Pxvalue) { final float scale = context.getresources (). Getdisplaymetri CS (). density; return (int) (Pxvalue/scale + 0.5f); } public static int dip2px (context context, float Dpvalue) { final float scale = context.getresources (). Getdisplaymetri CS (). density; return (int) (Dpvalue * scale + 0.5f); }
Interface adaptation issues on different Android models