Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static int dp2px(Context ctx, float dp) { float density = ctx.getResources().getDisplayMetrics().density; int px = (int) (dp * density + 0.5f);// 4.9->5 4.4->4 return px; } }