Java tutorial
//package com.java2s; import android.content.Context; import android.content.res.Resources; public class Main { public static int convertDIP2PX(Context context, float dip) { Resources resources = context.getResources(); float scale = resources.getDisplayMetrics().density; resources = null; return (int) (dip * scale + 0.5f * (dip >= 0 ? 1 : -1)); } }