dp与px之间的转换

来源:互联网 发布:网络代销挣钱吗 编辑:程序博客网 时间:2024/06/05 22:47
private static float density = -1F;    public static float getDensity(Context context) {        if (density <= 0F) {            density = context.getResources().getDisplayMetrics().density;        }        return density;    }    public static int dip2px(Context context, float dpValue) {        return (int) (dpValue * getDensity(context) + 0.5F);    }    public static int px2dip(Context context, float pxValue) {        return (int) (pxValue / getDensity(context) + 0.5F);    }

0 0
原创粉丝点击