Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.util.DisplayMetrics; public class Main { public static double pxToDp(Context context, double px) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); double dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); return dp; } }