Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.util.DisplayMetrics; public class Main { public static float dp2px(Context context, float size) { return size * context.getResources().getDisplayMetrics().density; } public static DisplayMetrics getDisplayMetrics(Context context) { return context.getResources().getDisplayMetrics(); } }