Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; public class Main { public static int px2sp(Context context, float pxValue) { return px2dp(context, pxValue); } public static int px2dp(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return Math.round(pxValue / scale); } }