Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static float dpFromPx(Context context, float f) { return f / context.getResources().getDisplayMetrics().density; } }