Android Dip to Pixel Convert spToPx(Context context, int spValue)

Here you can find the source of spToPx(Context context, int spValue)

Description

Convert sp value to px value

Parameter

Parameter Description
context The context of operation
spValue The dp value to be converted to px

Return

The px value

Declaration

public static int spToPx(Context context, int spValue) 

Method Source Code

//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);
    }
}

Related

  1. dpToPx(Context context, int dpValue)
  2. dpToPx(Context ctx, int dp)
  3. formatDipToPx(Context context, float dip)
  4. sp2px(Context context, float spValue)
  5. sp2px(Context context, float spValue)
  6. convertToPixel(Context context, float dp)
  7. getPixelFromDp(float dp, Context context)
  8. convertDptoPx(Context context, int dp)
  9. dip2px(Context context, int dip)