Android的Px与Dp转化工具类

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

    public class DensityUtils {  
        public static int Dp2Px(Context context, float dp) {   
            final float scale = context.getResources().getDisplayMetrics().density;   
            return (int) (dp * scale + 0.5f);   
        }   
           
        public static int Px2Dp(Context context, float px) {   
            final float scale = context.getResources().getDisplayMetrics().density;   
            return (int) (px / scale + 0.5f);   
        }   
    }