Here you can find the source of convertPxtoDp(Context context, int px)
public static int convertPxtoDp(Context context, int px)
//package com.java2s; import android.content.Context; public class Main { public static int convertPxtoDp(Context context, int px) { float scale = context.getResources().getDisplayMetrics().density; return (int) (px / scale + 0.5f); }/*from w ww .jav a2 s. c om*/ }