Android Dip to Pixel Convert dipsToPixels(Context aContext, int aDip)

Here you can find the source of dipsToPixels(Context aContext, int aDip)

Description

Converts the given DIPs into current device/resolution pixels.

License

Apache License

Parameter

Parameter Description
aContext - context required to retrieve device metrics
aDip - DIP value to convert to pixels.

Return

Rerturns the pixel count for the given DIP.

Declaration

static public int dipsToPixels(Context aContext, int aDip) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import android.content.Context;
import android.util.TypedValue;

public class Main {
    /**//from   w w  w  . ja va2 s . co  m
     * Converts the given DIPs into current device/resolution pixels.
     * @param aContext - context required to retrieve device metrics
     * @param aDip - DIP value to convert to pixels.
     * @return Rerturns the pixel count for the given DIP.
     * @author Ryan Fischbach
     */
    static public int dipsToPixels(Context aContext, int aDip) {
        float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                aDip, aContext.getResources().getDisplayMetrics());
        return Math.round(px);
    }
}

Related

  1. dip2px(Context context, float dipValue)
  2. dip2px(Context context, float dipValue)
  3. dip2px(Context context, float dpValue)
  4. dip2px(Context context, float dpValue)
  5. dipToPixel(int dip)
  6. convertDIP2PX(Context context, float dip)
  7. sp2px(Context context, float spValue)
  8. scaleDpToPixels(double value, Resources res)
  9. convertDpToPixel(float dp, Context context)