Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.util.TypedValue; public class Main { public static int pxToDp(int px, Context context) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px, context.getResources().getDisplayMetrics()); } }