Java tutorial
//package com.java2s; import android.content.Context; import android.util.DisplayMetrics; import android.util.Log; public class Main { public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; Log.e("desitiny", scale + ""); return (int) (dpValue * scale + 0.5f); } private static DisplayMetrics getDisplayMetrics(final Context context) { return context.getResources().getDisplayMetrics(); } }