Here you can find the source of getPixels(int dp, Context context)
public static int getPixels(int dp, Context context)
//package com.java2s; import android.content.Context; public class Main { public static int getPixels(int dp, Context context) { final float scale = context.getResources().getDisplayMetrics().density; int px = (int) (dp * scale + 0.5f); return px; }//from w w w . j a v a 2 s .co m }