List of utility methods to do Dip to Pixel Convert
float | convertToPixel(Context context, float dp) convert To Pixel return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
context.getResources().getDisplayMetrics());
|
float | getPixelFromDp(float dp, Context context) This method converts dp unit to equivalent pixels, depending on device density. Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
return dp * (metrics.densityDpi / 160f);
|
int | convertDptoPx(Context context, int dp) convert Dpto Px float scale = context.getResources().getDisplayMetrics().density; return (int) (dp * scale + 0.5f); |
int | dip2px(Context context, int dip) Convert dip to px value final float scale = context.getResources().getDisplayMetrics().density; return (int) (dip * scale + 0.5f); |
int | dipValue(Context context, int dip) dip Value return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, context.getResources().getDisplayMetrics()); |
int | dip2pixel(Context context, float n) dippixel int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, n, context.getResources() .getDisplayMetrics()); return value; |
int | dip2px(Context context, float dipValue) dippx final float scale = context.getResources().getDisplayMetrics().density; return (int) (dipValue * scale + 0.5f); |
int | dip2px(Context context, float dipValue) dippx final float scale = context.getResources().getDisplayMetrics().density; return (int) (dipValue * scale + 0.5f); |
int | dip2px(Context context, float dpValue) dippx final float scale = context.getResources().getDisplayMetrics().density; Log.e("desitiny", scale + ""); return (int) (dpValue * scale / 1.5 + 0.5f); |
int | dip2px(Context context, float dpValue) dippx final float scale = context.getResources().getDisplayMetrics().density; Log.e("desitiny", scale + ""); return (int) (dpValue * scale / 1.5 + 0.5f); |