Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; public class Main { public static int px2dip(Context context, int px) { float scale = context.getResources().getDisplayMetrics().density; return (int) (px / scale + 0.5f * (px >= 0 ? 1 : -1)); } }