Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static int px2sp(Context context, int px) { float density = context.getResources().getDisplayMetrics().scaledDensity; return (int) (px / density + 0.5f); } }