Example usage for android.util TypedValue COMPLEX_UNIT_DIP

List of usage examples for android.util TypedValue COMPLEX_UNIT_DIP

Introduction

In this page you can find the example usage for android.util TypedValue COMPLEX_UNIT_DIP.

Prototype

int COMPLEX_UNIT_DIP

To view the source code for android.util TypedValue COMPLEX_UNIT_DIP.

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is Device Independent Pixels.

Usage

From source file:Main.java

public static float dp2px(Resources resources, float dp) {
    float v = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
    return (int) (v + 0.5f);
}

From source file:Main.java

static public int getPixelFromDip(DisplayMetrics dm, float dip) {
    return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, dm) + 0.5f);
}

From source file:Main.java

public static int getDipToPx(Resources res, int dip) {
    int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, res.getDisplayMetrics());
    return pixel;
}

From source file:Main.java

public static int convertDPIntoPixel(int dp, Context context) {
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());
    return px;/*from   w  w  w  .j a v  a 2s  . co m*/
}

From source file:Main.java

public static float dipToPixels(float dip, Resources resource) {

    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, resource.getDisplayMetrics());
    return px;//from w  ww .  j av a  2 s  .c  o m

}

From source file:Main.java

public static final int getDpPx(int dp, DisplayMetrics displayMetrics) {
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, displayMetrics);
    return px;/*from w  w  w. j  av  a2  s.  c  o  m*/
}

From source file:Main.java

static int dp2px(int dp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            Resources.getSystem().getDisplayMetrics());
}

From source file:Main.java

public static int getPX(Context context, int dipValue) {
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue,
            context.getResources().getDisplayMetrics());
    return (int) px;
}

From source file:Main.java

public static float getPixelsFromDp(float dp) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            Resources.getSystem().getDisplayMetrics());
}

From source file:Main.java

static int dp(float dp, DisplayMetrics metrics) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
}