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 dpToPx(Context context, float dp) {

    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int sp2px(Context context, int dp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dp,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

protected static int dpToPx(Context context, int dp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

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

From source file:Main.java

public static int pxToDp(Context context, int px) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, px,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static float dp2px(float dp, Context context) {
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());
    return px;/*from  ww  w. j  av  a2 s .co  m*/
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

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