Here you can find the source of px2sp(Context context, float pxValue)
public static int px2sp(Context context, float pxValue)
//package com.java2s; import android.content.Context; public class Main { public static int px2sp(Context context, float pxValue) { final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; return (int) (pxValue / fontScale + 0.5f); }/*from w ww. j ava 2 s. c o m*/ }