Here you can find the source of dip2px(Context context, int dip)
public static int dip2px(Context context, int dip)
//package com.java2s; import android.content.Context; public class Main { /**/* w w w .j a v a 2s . com*/ * Convert dip to px value * * @author Sean Zheng * @CreateDate 2013-4-24 */ public static int dip2px(Context context, int dip) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dip * scale + 0.5f); } }