在鸿蒙操作系统中,1px 相对于 fp 是多少?

问题描述

谁能告诉 px:fp 比率或代码将 fp 转换为 px。
我正在构建一个 HarmonyOS 应用程序,我想将组件的宽度设置为 20fp,但 setWidth​(int width) 的宽度以 px 为单位。

Button button = new Button(getContext());
button.setWidth(width);

解决方法

HarmonyOS 提供了 AttrHelper 工具类来实现 fp 和 px 之间的转换。

AttrHelper.fp2px()

有关详细信息,请参阅此Docs