本文整理汇总了Java中android.util.TypedValue.COMPLEX_UNIT_SP属性的典型用法代码示例。如果您正苦于以下问题:Java TypedValue.COMPLEX_UNIT_SP属性的具体用法?Java TypedValue.COMPLEX_UNIT_SP怎么用?Java TypedValue.COMPLEX_UNIT_SP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.util.TypedValue
的用法示例。
在下文中一共展示了TypedValue.COMPLEX_UNIT_SP属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyDimension
/**
* 各种单位转换
* <p>该方法存在于TypedValue</p>
*
* @param unit 单位
* @param value 值
* @param metrics DisplayMetrics
* @return 转换结果
*/
public static float applyDimension(final int unit, final float value, final DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例2: applyDimension
public static float applyDimension(int unit, float value, DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例3: applyDimension
/**
* 各种单位转换
* <p>该方法存在于TypedValue</p>
*
* @param unit 单位
* @param value 值
* @param metrics DisplayMetrics
* @return 转换结果
*/
public static float applyDimension(int unit, float value, DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例4: getUnit
@PixelValue.PixelUnit
private static int getUnit(String s) throws ParametersParseException {
switch (s.toLowerCase()) {
default:
throw new ParametersParseException("Unknown unit " + s);
case "px":
return TypedValue.COMPLEX_UNIT_PX;
case "dp":
case "dip":
return TypedValue.COMPLEX_UNIT_DIP;
case "sp":
return TypedValue.COMPLEX_UNIT_SP;
case "em":
return PixelValue.EM;
}
}
示例5: applyDimension
/**
* 各种单位转换
* <p>该方法存在于TypedValue
*/
public static float applyDimension(int unit, float value, DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例6: getPxValue
public final float getPxValue() {
switch (unit) {
case EM:
return this.value / 16.f;
case TypedValue.COMPLEX_UNIT_PX:
return this.value;
case TypedValue.COMPLEX_UNIT_SP:
return ParametersUtils.spToPx(this.value);
case TypedValue.COMPLEX_UNIT_DIP:
return ParametersUtils.dpToPx(this.value);
default:
return value;
}
}
示例7: fromSp
public Builder fromSp(float fromSize) { unit = TypedValue.COMPLEX_UNIT_SP; return from(fromSize); }
示例8: toSp
public Builder toSp(float toSize) { unit = TypedValue.COMPLEX_UNIT_SP; return to(toSize); }