List of utility methods to do Pixel to Dip Convert
int | pixelsToDpi(Resources res, int pixels) pixels To Dpi return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) pixels, res.getDisplayMetrics()); |
int | convertPX2DIP(Context context, float px) convert PXDIP Resources resources = context.getResources(); float scale = resources.getDisplayMetrics().density; resources = null; return (int) (px / scale + 0.5f * (px >= 0 ? 1 : -1)); |
int | px2dip(Context context, float px) pxdip final float scale = context.getResources().getDisplayMetrics().density; return (int) (px / scale + 0.5f); |
int | px2sp(Context context, float pxValue) pxsp final float scale = context.getResources().getDisplayMetrics().scaledDensity; return (int) (pxValue / scale + 0.5f); |
float | getPixelsFromDIP(Context context, int dipValue) get Pixels From DIP if (context != null) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, context.getResources().getDisplayMetrics()); return dipValue; |
float | pixel2dip(Context context, float n) pixeldip Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float dp = n / (metrics.densityDpi / 160f); return dp; |
int | convertPixtoDip(int pixel, Context context) convert Pixto Dip float scale = getDensity(context); return (int) ((pixel - 0.5f) / scale); |