标签:resources return metrics class 转换 div public final nal
1 /** 2 * 3 * px dip 转换 4 */ 5 public class DensityUtil { 6 7 /** 8 * 根据手机分辨率 dip 转 px 9 */ 10 static public int dip2px(Context context,float dpValue){ 11 final float scale = context.getResources().getDisplayMetrics().density; 12 return (int) (dpValue*scale+0.5f); 13 } 14 /** 15 * 根据手机分辨率 px 转 dip 16 */ 17 static public int px2dip(Context context, float pxValue){ 18 final float scale = context.getResources().getDisplayMetrics().density; 19 return (int)(pxValue/scale+0.5f); 20 } 21 }
标签:resources return metrics class 转换 div public final nal
原文地址:https://www.cnblogs.com/the-wang/p/9060694.html