Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; public class Main { /** * The mContext. */ private static Context mContext; public static int px2sp(float value) { final float scale = mContext.getResources().getDisplayMetrics().scaledDensity; return (int) (value / scale + 0.5f); } public static int px2sp(float value, Context context) { final float scale = context.getResources().getDisplayMetrics().scaledDensity; return (int) (value / scale + 0.5f); } }