Java tutorial
//package com.java2s; import android.content.Context; import android.util.Log; public class Main { public static int dip2px(Context ctx, float dpValue) { final float density = ctx.getResources().getDisplayMetrics().density; Log.i("density", "density=" + density); return (int) (dpValue * density + 0.5f); } }