public static float convertPixelToDp ( Context context , float px ) { Resources resources = context . getResources ( ) ; DisplayMetrics metrics = resources . getDisplayMetrics ( ) ; return px / ( metrics . densityDpi / 160f ) ; }
This method converts device specific pixels to density independent pixels .