Here you can find the source of dp2px(Context context, float dp)
public static int dp2px(Context context, float dp)
//package com.java2s; import android.content.Context; import android.util.DisplayMetrics; import android.util.TypedValue; public class Main { public static int dp2px(Context context, float dp) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);/*from w ww .ja va2s.co m*/ } }