Here you can find the source of px2dip(Context context, int px)
public static int px2dip(Context context, int px)
//package com.java2s; import android.content.Context; public class Main { /**// w w w .j a v a 2 s .com * Convert px to dip value * * @author Sean Zheng * @CreateDate 2013-4-24 */ public static int px2dip(Context context, int px) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (px / scale + 0.5f); } }