Here you can find the source of px2dip(Context context, float pxvalue)
public static int px2dip(Context context, float pxvalue)
//package com.java2s; //License from project: Apache License import android.content.Context; public class Main { public static int px2dip(Context context, float pxvalue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxvalue / scale + 0.5f); }// w w w. j a v a2s .co m }