Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static int px2dp(float value, Context context) { final float scale = context.getResources().getDisplayMetrics().densityDpi; return (int) ((value * 160) / scale + 0.5f); } }