/** 像素转换工具 */ public class PixelUtils { /** * The context. */ private static Context mContext = CustomApplcation.getInstance(); /** * dp转 px. * * @param value the value * @return the int */ public static int dp2px(float value) { final float scale = m
现在由于用到了,使用代码进行动态布局,所以需要进行px于dp之间的转换. 现将其封装为方法,以便于调用. public int DpToPx(Context context,float dp){ float scale=context.getResource().getDisplayMetrics().density; return (int) (dp * scale + 0.5f); } public int PxToDp(Context context,float px){ float s