【HarmonyOS NEXT】在Component中通过px2vp转换的数据前后不一致

【关键字】

px2vp像素单位转换 / @ohos.app.ability.UIAbility组件 / @ohos.window (窗口)模块 / windowStage.loadContent

【问题描述】

通过getWindowAvoidArea.topRect.heigth获取到状态栏的高度为126,这个高度设置为组件的margintop,在工具类里面通过px2vp 126 = 126, 而在component中转换后得到的值却不一样,是什么原因?

screenutils(hsp): 在entryablity中的onWindowCreate中初始化:

import window from '@ohos.window';
import { LogUtils } from './LogUtils';
import { DS_COMPONENTS_TAG } from '../DSComponentsContants';

export class ScreenUtils {
private static TAG: string = `${DS_COMPONENTS_TAG}-${ScreenUtils.name}`
private static _statusBarHeight: number = 0
private static _navigationBarHeight: number = 0
private static _screenWidth: number = 0
private static _screenHeight: number = 0
private static _contentHeight: number = 0
private static _contentWidth: number = 0

static get statusBarHeight(): number {
return ScreenUtils._statusBarHeight
}

static get navigationBarHeight(): number {
return ScreenUtils._na
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值