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