Android Dip to Pixel Convert dpToPx(Context context, int dpValue)

Here you can find the source of dpToPx(Context context, int dpValue)

Description

Convert dp value to px value

Parameter

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

Return

The px value

Declaration

public static int dpToPx(Context context, int dpValue) 

Method Source Code

//package com.java2s;
import android.content.Context;
import android.util.DisplayMetrics;

public class Main {
    /**/*from w  w w  . ja v  a2  s  .c  om*/
     * Convert dp value to px value
     * @param context The context of operation
     * @param dpValue The dp value to be converted to px
     * @return The px value
     */
    public static int dpToPx(Context context, int dpValue) {
        DisplayMetrics displayMetrics = context.getResources()
                .getDisplayMetrics();
        return (int) ((dpValue * displayMetrics.density) + 0.5);
    }
}

Related

  1. dip2px(Context context, float dpvalue)
  2. dip2px(float dipValue, float scale)
  3. dipToPixels(Context context, float dipValue)
  4. dp2px(Context context, float dp)
  5. dpToPixel(Context context, int dp)
  6. dpToPx(Context ctx, int dp)
  7. formatDipToPx(Context context, float dip)
  8. sp2px(Context context, float spValue)
  9. sp2px(Context context, float spValue)