List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:Main.java
public static int convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); int px = Math.round(dp * (metrics.densityDpi / 160f)); // bit fuzzy, but probably won't be big issues. return px;//ww w.jav a 2 s .c o m }
From source file:Main.java
public static float dpToPx(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 convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return px;//from ww w.j av a 2s .c o m }
From source file:Main.java
public static int convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return (int) px; }
From source file:Main.java
public static int convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return Math.round(px); }
From source file:Main.java
public static float convertPixelsToDp(Context context, float pxValue) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return pxValue / (metrics.densityDpi / 160f); }
From source file:Main.java
public static int convertPixelsToDp(float px, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float dp = px / (metrics.densityDpi / 160f); return (int) dp; }
From source file:Main.java
public static float getDpi(Context context) { // will either be DENSITY_LOW, DENSITY_MEDIUM or DENSITY_HIGH //For Samsung Galaxy sIII : 320 dpi Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); int dpiClassification = metrics.densityDpi; return dpiClassification; }
From source file:Main.java
public static int pixelsToDpi(Resources resources, int i) { return (int) TypedValue.applyDimension(1, (float) i, resources.getDisplayMetrics()); }
From source file:Main.java
public static float dpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return dp * (metrics.densityDpi / 160f); }