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