Here you can find the source of convertPixelsToDp(Context context, float pxValue)
public static float convertPixelsToDp(Context context, float pxValue)
//package com.java2s; import android.content.Context; import android.content.res.Resources; import android.util.DisplayMetrics; public class Main { public static float convertPixelsToDp(Context context, float pxValue) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return pxValue / (metrics.densityDpi / 160f); }/*from www. j ava 2 s.c o m*/ }