官方提供了工具类AttrHelper,可实现fp、vp、px相互转换:
https://developer.harmonyos.com/cn/docs/documentation/doc-references/attrhelper-0000001054518726
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 |
|