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);
}
dp与px之间的转换
最新推荐文章于 2022-11-14 16:40:18 发布