Java tutorial
//package com.java2s; import android.content.res.Resources; public class Main { public static int px2dp(float pxValue) { final float scale = Resources.getSystem().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); } }