Tag:android picture px dp
</pre><pre name= "code" class= "java" >package Com.lengxiaocai.myutil.screentool;import android.content.context;/** * * @ClassName: Screentool * * @Description: Screen pixel detection * * @author Yazhizhao * * @date 2014-5-6 a.m. 11:47:07 */public class Screentool {public static int dip2px (context context, float Dpvalue) {final Flo At scale = Context.getresources (). Getdisplaymetrics (). Density;return (Int.) (Dpvalue * scale + 0.5f);} public static int Px2dip (context context, float Pxvalue) {final float scale = context.getresources (). Getdisplaymetrics (). Density;return (int) (Pxvalue/scale + 0.5f);} public static int px2sp (float pxvalue, float fontscale) {return (int) (Pxvalue/fontscale + 0.5f);} public static int sp2px (float spvalue, float fontscale) {return (int) (Spvalue * fontscale + 0.5f);}}