Here you can find the source of dpToPx(Context ctx, int dp)
public static int dpToPx(Context ctx, int dp)
//package com.java2s; import android.content.Context; import android.util.DisplayMetrics; public class Main { public static int dpToPx(Context ctx, int dp) { DisplayMetrics displayMetrics = ctx.getResources() .getDisplayMetrics();/* w ww. j a va2s . c o m*/ int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); return px; } }