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