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 int ConvertToPx(Context c, int dip) {
    Resources r = c.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());
    return (int) px;
}

From source file:Main.java

public static int dpToPx(Context context, int dp) {
    Resources r = context.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
    return (int) px;
}

From source file:Main.java

public static int dipToPx(Context context, int dip) {
    Resources r = context.getResources();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());
}

From source file:Main.java

public static int getPixels(Context c, int dipValue) {
    Resources r = c.getResources();
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics());
    return px;//  w  w  w .java2 s  . c  o  m
}

From source file:Main.java

public static int convertDipToPx(Context context, int dp) {
    Resources r = context.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
    return (int) px;
}

From source file:Main.java

public static int dip2px(Context context, float dpValue) {
    Resources r = context.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, r.getDisplayMetrics());
    return (int) px;
}

From source file:Main.java

public static int convertDpToPixel(Context context, int dp) {
    Resources r = context.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
    return Math.round(px);
}

From source file:Main.java

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

From source file:Main.java

/**
 *  Converts 1 dip (device independent pixel) into its equivalent physical pixels
 *///from  w  ww  .  ja  v  a2 s. com
public static float getDpiToPix(Context ctx) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, ctx.getResources().getDisplayMetrics());
}

From source file:Main.java

public static float convertDpToFloatPixel(Context context, float dp) {
    Resources r = context.getResources();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
}