px2dp专题

dp和px的转化(dp2px,px2dp)

public class DensityUtil {/*** 根据手机的分辨率从 dp 的单位 转成为 px(像素).** @param dpValue dpValue* @return px*/public static int dp2px(float dpValue) {return (int) Math.ceil(TypedValue.applyDimension(TypedValue.CO

dp2px px2dp

/*** 将dp转换成px* @param context* @param dpValue* @return*/public static int dip2px(Context context,float dpValue){final float scale = context.getResources ().getDisplayMetrics ().density;return (int) (d