List of utility methods to do Pixel to Dip Convert
float | convertPixelsToDp(Context context, float pxValue) convert Pixels To Dp Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
return pxValue / (metrics.densityDpi / 160f);
|
float | convertPixelsToDp(Context ctx, float px) This method converts device specific pixels to device independent pixels. Resources resources = ctx.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
return px / (metrics.densityDpi / 160f);
|
int | convertPixelsToSp(Context context, float pxValue) convert Pixels To Sp Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return (int) (pxValue / metrics.scaledDensity + 0.5f); |
int | px2dip(Context context, float pxValue) pxdip final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); |
int | px2dip(Context context, float pxValue) pxdip final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); |
int | px2dip(Context context, float pxValue) pxdip final float scale = getDensity(context); return (int) (pxValue / scale + 0.5f); |
int | px2dip(Context context, float pxValue) px to dip final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); |
int | px2dip(Context context, float pxvalue) pxdip final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxvalue / scale + 0.5f); |
int | px2dip(float pxValue, float scale) pxdip return (int) (pxValue / scale + 0.5f); |
int | px2dp(Context context, int px) pxdp DisplayMetrics metrics = context.getResources().getDisplayMetrics(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px, metrics); |