List of utility methods to do Dip to Pixel Convert
int | dipToPixel(int dip) Converts DIP to pixels. return (int) (dip * scale + 0.5f); |
int | dipsToPixels(Context aContext, int aDip) Converts the given DIPs into current device/resolution pixels. float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, aDip, aContext.getResources().getDisplayMetrics()); return Math.round(px); |
int | convertDIP2PX(Context context, float dip) convert DIPPX Resources resources = context.getResources(); float scale = resources.getDisplayMetrics().density; resources = null; return (int) (dip * scale + 0.5f * (dip >= 0 ? 1 : -1)); |
int | sp2px(Context context, float spValue) sppx final float scale = context.getResources().getDisplayMetrics().scaledDensity; return (int) (spValue * scale + 0.5f); |
int | scaleDpToPixels(double value, Resources res) scale Dp To Pixels final float scale = res.getDisplayMetrics().density; return (int) Math.round(value * scale); |
float | convertDpToPixel(float dp, Context context) convert Dp To Pixel Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return px; |
int | convertDpToPixel(float dp, Resources resources) convert Dp To Pixel DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return (int) px; |
int | dipToPixels(int dip) dip To Pixels float density = resources.getDisplayMetrics().density; int valuePixels = (int) (dip * density + 0.5f); return valuePixels; |
int | sp2px(Context context, float spValue) sppx Resources resources = context.getResources(); final float fontScale = resources.getDisplayMetrics().scaledDensity; resources = null; return (int) (spValue * fontScale + 0.5f); |
float | sp2px(float sp, Context context) sppx final float scale = context.getResources().getDisplayMetrics().scaledDensity; return sp * scale; |