public class AttrHelper extends Object
| 构造器 | 说明 |
|---|---|
AttrHelper() |
Default constructor used to create a
AttrHelper instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static int |
convertDimensionToPix(String value,
float density,
int defaultValue) |
Converts a dimension value to a number of pixels.
|
static int |
convertDimensionToPix(Context context,
String value,
int defaultValue) |
Converts a dimension value into a pixel value.
|
static BlendMode |
convertValueToBlendMode(String value,
BlendMode defaultValue) |
Converts a value from a character string to an integer.
|
static boolean |
convertValueToBoolean(String value,
boolean defaultValue) |
Converts a value from a character string to a Boolean value.
|
static Color |
convertValueToColor(String value) |
Converts a string into a
Color object. |
static ColorMatrix |
convertValueToColorMatrix(int value) |
Converts a value from an int to a
ColorMatrix object. |
static Element |
convertValueToElement(String value) |
Converts a string into a
Element object. |
static float |
convertValueToFloat(String value,
float defaultValue) |
Converts a character string to a floating point value.
|
static int |
convertValueToInt(String value,
int defaultValue) |
Converts a value from a character string to an integer.
|
static long |
convertValueToLong(String value,
long defaultValue) |
Converts a string to a long value.
|
static int |
fp2px(float value,
float density) |
Converts a font-size pixel (fp) to a pixel value based on the screen density.
|
static int |
fp2px(float value,
float density,
float fontRatio) |
Converts a font-size pixel (fp) value to a pixel value based on the screen density and font ratio.
|
static int |
fp2px(float value,
Context context) |
Converts a font-size pixel (fp) to a pixel value based on the screen context.
|
static float |
getDensity(Context context) |
Obtains the display density.
|
static float |
getFontRatio(Context context) |
Obtains the font ratio.
|
static float |
px2fp(int value,
Context context) |
Converts a pixel to a font-size pixel based on the screen context.
|
static float |
px2vp(int value,
Context context) |
Converts a pixel to a virtual pixel based on the screen context.
|
static int |
vp2px(float value,
float density) |
Converts a virtual pixel (vp) to a pixel value based on the screen density.
|
static int |
vp2px(float value,
Context context) |
Converts a virtual pixel (vp) to a pixel value based on the screen context.
|
public AttrHelper()
AttrHelper instance.public static float getDensity(Context context)
context - Indicates the application context.public static float getFontRatio(Context context)
context - Indicates the application context.public static int convertValueToInt(String value, int defaultValue)
If the value is empty, the value specified by defaultValue is returned.
value - Indicates the value to convert.defaultValue - Indicates the default value.public static BlendMode convertValueToBlendMode(String value, BlendMode defaultValue)
If the value is empty, the value specified by defaultValue is returned.
value - Indicates the value to convert.defaultValue - Indicates the default value.BlendMode value after conversion.public static ColorMatrix convertValueToColorMatrix(int value)
ColorMatrix object.value - Indicates the int color value to convert.ColorMatrix value after conversion.public static boolean convertValueToBoolean(String value, boolean defaultValue)
Ensure that the Boolean value is either true or false. Otherwise, an exception will occur.
value - Indicates the value to convert.defaultValue - Indicates the default value.public static float convertValueToFloat(String value, float defaultValue)
defaultValue is returned.value - Indicates the character string to convert.defaultValue - Indicates the default value.public static long convertValueToLong(String value, long defaultValue)
value - Indicates the string value.defaultValue - Indicates the default value.public static Element convertValueToElement(String value)
Element object.value - Indicates the string to convert.Element object.public static Color convertValueToColor(String value)
Color object.value - Indicates the string to convert.Color object.public static int convertDimensionToPix(String value, float density, int defaultValue)
value - Indicates the dimension value to convert.density - Indicates the screen density.defaultValue - Indicates the default value.public static int convertDimensionToPix(Context context, String value, int defaultValue)
context - Indicates the application context.value - Indicates the dimension value to convert.defaultValue - Indicates the default value.public static int vp2px(float value,
float density)
value - Indicates the vp value to convert.density - Indicates the screen density.getDensity(Context)public static int vp2px(float value,
Context context)
value - Indicates the vp value to convert.context - Indicates the screen context.public static int fp2px(float value,
float density)
value - Indicates the fp value to convert.density - Indicates the screen density.getDensity(Context)public static int fp2px(float value,
float density,
float fontRatio)
value - Indicates the fp value to convert.density - Indicates the screen density.fontRatio - Indicates the font ratio.getDensity(Context),
getFontRatio(Context)public static int fp2px(float value,
Context context)
value - Indicates the fp value to convert.context - Indicates the screen context.public static float px2vp(int value,
Context context)
value - Indicates the pixel to convert.context - Indicates the screen context.public static float px2fp(int value,
Context context)
value - Indicates the pixel to convert.context - Indicates the screen context.