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