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