Here you can find the source of dpToPixel(Context context, int dp)
public static int dpToPixel(Context context, int dp)
//package com.java2s; import android.content.Context; public class Main { public static int dpToPixel(Context context, int dp) { if (context == null) { return 0; }//from w w w . j a v a 2 s . c om return (int) (context.getResources().getDisplayMetrics().density * dp); } }