Java tutorial
//package com.java2s; import android.content.Context; public class Main { /** * @param context * @param px * @return */ public static float px2sp(Context context, Float px) { if (context == null) { return px.intValue(); } float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity; return px / scaledDensity; } }