Example usage for android.util TypedValue applyDimension

List of usage examples for android.util TypedValue applyDimension

Introduction

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

Prototype

public static float applyDimension(int unit, float value, DisplayMetrics metrics) 

Source Link

Document

Converts an unpacked complex data value holding a dimension to its final floating point value.

Usage

From source file:Main.java

public static float dip2px(Context context, float dipValue) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static float convertPXtoDP(Context context, float pxVal) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, pxVal,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int dipsToPix(Context context, float dps) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dps,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int dp2px(Context context, int dp) {
    return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics()));
}

From source file:Main.java

public static float dpToPx(Resources res, float dp) {
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, res.getDisplayMetrics());
    return px;/*  w w  w. j ava 2  s  .  co m*/
}

From source file:Main.java

public static int dipToPx(Context context, float dpValue) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

private static int getDpToPx(int dp, Context context) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());

}

From source file:Main.java

public static float convertDPtoPX(Context context, float dpVal) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int pxToDp(final int n, final Context context) {
    return (int) TypedValue.applyDimension(0, (float) n, context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int getTextSize(Context context, int size) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size,
            context.getResources().getDisplayMetrics());

}