Java tutorial
//package com.java2s; import android.content.res.Resources; import android.util.DisplayMetrics; import android.util.TypedValue; public class Main { public static int dip2Px(Resources res, int dip) { DisplayMetrics dm = res.getDisplayMetrics(); return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, dm)); } }