@@ -0,0 +1,896 @@
+package com.example.administrator.myapplication;%0A%0Aimport android.content.Context;%0Aimport android.util.TypedValue;%0A%0A/**%0A * %E5%8D%95%E4%BD%8D%E8%BD%AC%E6%8D%A2%3Cp%3E%0A * %E5%8F%AF%E6%9F%A5%E7%9C%8B%7B@link TypedValue%7D%E7%9A%84applyDimension()%0A */%0Apublic class DensityUtil %7B%0A%0A%09public static float px2dp(Context context, float pxValue) %7B%0A%09%09final float scale = context.getResources().getDisplayMetrics().density;%0A%09%09return pxValue / scale;%0A%09%7D%0A%0A%09public static float dp2px(Context context, float dipValue) %7B%0A%09%09final float scale = context.getResources().getDisplayMetrics().density;%0A%09%09return dipValue * scale;%0A%09%7D%0A%0A%09public static float px2sp(Context context, float pxValue) %7B%0A%09%09final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;%0A%0A%09%09return pxValue / fontScale;%0A%09%7D%0A%0A%09public static float sp2px(Context context, float spValue) %7B%0A%09%09final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;%0A%09%09return spValue * fontScale;%0A%09%7D%0A%7D%0A

add DensityUtil