daimajia / AnimationEasingFunctions

Android Animation Easing Functions. Let's make animation more real!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

不用传context的dp 转 px工具

gb18030 opened this issue · comments

commented

public class DisplayUtil {

static {
    DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
    density = displayMetrics.density;
    scaledDensity = displayMetrics.scaledDensity;
}
private static float density;
private static float scaledDensity;

public static int px2dip(float px){
    return (int) (px/density + 0.5f);
}

public static float dip2px(float dp){
    return dp*density;
}
public static int px2sp(float px){
    return (int) (px/scaledDensity + 0.5f);
}
public static float sp2px(float sp){
    return  sp*scaledDensity;
}

}