List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:Main.java
private static float convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); return px;// w ww . j av a 2 s. com }
From source file:Main.java
public static float convertPixelsToDp(float px, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return px / (metrics.densityDpi / 160f); }
From source file:Main.java
public static float dip2px(Context context, float dpValue) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dpValue * (metrics.densityDpi / 160f); return px;/*from ww w . j a v a 2s. com*/ }
From source file:Main.java
public static float getRateDpToPixel(Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float rateDpToPixel = ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); return rateDpToPixel; }
From source file:Main.java
public static float convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return dp * (metrics.densityDpi / 160f); }
From source file:Main.java
public static float px2dip(Context context, float pxValue) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float dp = pxValue / (metrics.densityDpi / 160f); return dp;/*w ww . ja v a2 s . c om*/ }
From source file:Main.java
public static float convertDpToPixel(Context context, float dpValue) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return dpValue * (metrics.densityDpi / 160f); }
From source file:Main.java
public static float convertDpToPixel(float dp, Activity context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return px;//w ww . j a v a 2s . c om }
From source file:Main.java
public static int convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); int px = (int) (dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)); return px;//from ww w . j a v a2s . c o m }
From source file:Main.java
public static int converSpToPixel(Context context, float spValue) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return (int) (spValue * metrics.scaledDensity + 0.5f); }