Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static int dp2px(float value, Context context) { final float scale = context.getResources().getDisplayMetrics().densityDpi; return (int) (value * (scale / 160) + 0.5f); } }