Convert pixel to sp - Android android.graphics

Android examples for android.graphics:Pixel

Description

Convert pixel to sp

Demo Code

import android.content.Context;
import java.text.SimpleDateFormat;
import java.util.Date;

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 www .j a  v a  2s  .c o  m*/

}

Related Tutorials