/** * 将dp转换成px * * @param dp * @return */ public static float dpToPx(float dp) { return(dp * AppUtils.getAppContext().Resources.DisplayMetrics.Density); }
/** * 获取屏幕高度 * * @return */ public static int getScreenHeight() { return(AppUtils.getAppContext().Resources.DisplayMetrics.HeightPixels); }
/** * 获取屏幕宽度 * * @return */ public static int getScreenWidth() { return(AppUtils.getAppContext().Resources.DisplayMetrics.WidthPixels); }
/** * 将sp值转换为px值 * * @param spValue * @return */ public static float spToPx(float spValue) { return(spValue * AppUtils.getAppContext().Resources.DisplayMetrics.ScaledDensity); }
/** * 将px值转换为sp值 * * @param pxValue * @return */ public static float pxToSp(float pxValue) { return(pxValue / AppUtils.getAppContext().Resources.DisplayMetrics.ScaledDensity); }
/** * 将px转换成dp * * @param px * @return */ public static float pxToDp(float px) { return(px / AppUtils.getAppContext().Resources.DisplayMetrics.Density); }