HarmonyOS margin中top和bottom使用百分比时,算出实际的px不对 17:22:04?

操作步骤:

1、初始化设置margin top 0%。

2、查看日志:

screenInfo width=1260, height=2720
current margin top 0%
new Area: x = 0px, y = 125.99999999999999px
margin top diff = 125.99999999999999px

3、点击按钮将margin top修改为1%,后查看日志:

change margin top 1%
new Area: x = 0px, y = 138px
margin top diff = 12.000000000000004px

预期:margin top diff应该为1% * height(2720)= 27.2 px,但这里是12px。

阅读 513
1 个回答

不建议直接使用百分比,可以使用

.margin({ top: px2vp(display.getDefaultDisplaySync().height*0.01)})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进