Here you can find the source of dip2px(Context context, float dpValue)
public static int dip2px(Context context, float dpValue)
//package com.java2s; import android.content.Context; public class Main { /**// w ww. java2 s .c o m * dip to px */ public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } }