Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static int dip2px(Context contxt, int dip) { float density = contxt.getResources().getDisplayMetrics().density; return (int) (dip * density + 0.5); } }