Java tutorial
//package com.java2s; import android.content.Context; public class Main { private static float distance(Context context, float diff) { float distanceInPx = (float) Math.sqrt(diff * diff); return pxToDp(context, distanceInPx); } private static float pxToDp(Context context, float px) { return px / context.getResources().getDisplayMetrics().density; } }