Here you can find the source of pxToSp(Context context, int pxValue)
Parameter | Description |
---|---|
context | The context of operation |
pxValue | The sx value to be converted to dp |
public static int pxToSp(Context context, int pxValue)
//package com.java2s; import android.content.Context; import android.util.DisplayMetrics; public class Main { /**// ww w .j a v a2 s. c om * Convert px value to sp value * @param context The context of operation * @param pxValue The sx value to be converted to dp * @return The sp value */ public static int pxToSp(Context context, int pxValue) { DisplayMetrics displayMetrics = context.getResources() .getDisplayMetrics(); return (int) ((pxValue / displayMetrics.scaledDensity) + 0.5); } }