public class DisplayUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected static float |
PIXEL_DP_RATIO
The ratio, which can be used to convert values, which are measured in pixels, into values,
which are measured in dp, and vice versa.
|
| Modifier and Type | Method and Description |
|---|---|
static float |
dpToPixels(android.content.Context context,
float dp)
Converts a
Float value, which is measured in dp, into a value, which is measured in
pixels. |
static int |
dpToPixels(android.content.Context context,
int dp)
Converts an
Integer value, which is measured in dp, into a value, which is measured
in pixels. |
static float |
pixelsToDp(android.content.Context context,
float pixels)
Converts a
Float value, which is measured in pixels, into a value, which is measured
in dp. |
static int |
pixelsToDp(android.content.Context context,
int pixels)
Converts an
Integer value, which is measured in pixels, into a value, which is
measured in dp. |
@VisibleForTesting protected static final float PIXEL_DP_RATIO
public static int pixelsToDp(android.content.Context context,
int pixels)
Integer value, which is measured in pixels, into a value, which is
measured in dp.context - The context, which should be used to retrieve the device's display metrics, as an
instance of the class Context. The context may not be nullpixels - The pixel value, which should be converted, as an Integer valueInteger value. The value might be roundedpublic static float pixelsToDp(android.content.Context context,
float pixels)
Float value, which is measured in pixels, into a value, which is measured
in dp.context - The context, which should be used to retrieve the device's display metrics, as an
instance of the class Context. The context may not be nullpixels - The pixel value, which should be converted, as a Float valueFloat valuepublic static int dpToPixels(android.content.Context context,
int dp)
Integer value, which is measured in dp, into a value, which is measured
in pixels.context - The context, which should be used to retrieve the device's display metrics, as an
instance of the class Context. The context may not be nulldp - The dp value, which should be converted, as an Integer valueInteger value. The value might be roundedpublic static float dpToPixels(android.content.Context context,
float dp)
Float value, which is measured in dp, into a value, which is measured in
pixels.context - The context, which should be used to retrieve the device's display metrics, as an
instance of the class Context. The context may not be nulldp - The dp value, which should be converted, as a Float valueFloat value