Android Dip to Pixel Convert dip2Px(Context context, float dipValue)

Here you can find the source of dip2Px(Context context, float dipValue)

Description

dip Px

Declaration

public static int dip2Px(Context context, float dipValue) 

Method Source Code

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

public class Main {

    public static int dip2Px(Context context, float dipValue) {
        /**//from  www.ja  v a  2s  . c o m
         * return
         * Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
         * value, context.getResources().getDisplayMetrics()));
         */
        final float scale = getDensity(context);
        return (int) (dipValue * scale + 0.5f);
    }

    /**
     * 
     * @param context
     * @return
     */
    public static float getDensity(Context context) {
        return context.getResources().getDisplayMetrics().density;
    }
}

Related

  1. convertDpToPixel(Context context, float dpValue)
  2. convertDpToPixel(Context ctx, float dp)
  3. dip2pixel(Context context, int dip)
  4. dip2px(Context context, float dipValue)
  5. getPixels(int dp, Context context)
  6. dip2px(Context context, float dpValue)
  7. dip2px(Context context, float dpValue)
  8. dip2px(Context context, float dpvalue)
  9. dip2px(float dipValue, float scale)