Java tutorial
//package com.java2s; //License from project: Apache License import android.content.res.Resources; public class Main { public static float getDpFromPixels(int px) { return px / Resources.getSystem().getDisplayMetrics().density; } }