Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; public class Main { public static int dip2px(Context context, int dip) { float scale = context.getResources().getDisplayMetrics().density; return (int) (dip * scale + 0.5f * (dip >= 0 ? 1 : -1)); } }