@@ -0,0 +1,1285 @@
+package com.ce.game.myapplication.util;%0A%0Aimport android.content.Context;%0A%0A%0A/**%0A * author : zhangy%0A *%0A * des : %E5%83%8F%E7%B4%A0%E5%B7%A5%E5%85%B7%E7%B1%BB%0A *%0A * date : 2016/6/7%0A */%0Apublic class PixelUtil %7B%0A%09/**%0A%09 * dip%E8%BD%AC%E6%8D%A2%E6%88%90px%0A%09 * %0A%09 * @param context%0A%09 * @param dipValue%0A%09 * @return%0A%09 */%0A%09public static int dip2px(Context context, float dipValue) %7B%0A%09    try%7B%0A    %09%09final float scale = context.getResources()%0A    %09%09%09%09.getDisplayMetrics().density;%0A    %09%09return (int) (dipValue * scale + 0.5f);%0A%09    %7Dcatch(Exception e)%7B%0A%09%09%7D%0A%09    return (int)dipValue;%0A%09%7D%0A%0A%09/**%0A%09 * px %E8%BD%AC%E6%8D%A2%E6%88%90dip%0A%09 * %0A%09 * @param context%0A%09 * @param pxValue%0A%09 * @return%0A%09 */%0A%09public static int px2dip(Context context, float pxValue) %7B%0A%09%09final float scale = context.getResources()%0A%09%09%09%09.getDisplayMetrics().density;%0A%09%09return (int) (pxValue / scale + 0.5f);%0A%09%7D%0A%09/**%0A%09 * PX%E8%BD%AC%E6%8D%A2%E6%88%90SP%0A%09 * @param pxValue%0A%09 * @return%0A%09 */%0A%09public static int px2sp(Context context, float pxValue) %7B%0A%09%09final float fontScale = context.getResources()%0A%09%09%09%09.getDisplayMetrics().scaledDensity;%0A%09%09return (int) (pxValue / fontScale + 0.5f);%0A%09%7D%0A%09/**%0A%09 * SP%E8%BD%AC%E6%8D%A2%E4%B8%BAPX%0A%09 * @param spValue%0A%09 * @return%0A%09 */%0A%09public static int sp2px(Context context, float spValue) %7B%0A        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;%0A        return (int) (spValue * fontScale + 0.5f);  %0A    %7D%0A%7D%0A

add util