DensityUtil

public class DensityUtil {   
   
    public static int dip2px(Context context, float dpValue) {   
        final float scale = context.getResources().getDisplayMetrics().density;   
        int value=(int) (dpValue * scale + 0.5f);   
        return value;   
    }   
   
    public static int px2dip(Context context, float pxValue) {   
        final float scale = context.getResources().getDisplayMetrics().density;   
        int value=(int)(pxValue / scale + 0.5f);  
        return value;   
    }   
}   
 

你可能感兴趣的:(util)