当前位置:网站首页>OpenHarmony像素单位(eTS)
OpenHarmony像素单位(eTS)
2022-08-05 14:12:00 【华为云】
ArkUI开发框架提供了 4 种像素单位供开发者使用,分别是: px 、 vp 、 fp 和 lpx ,框架采用vp为基准数据单位。它们之间的区别如下表所示:
| 名称 | 描述 |
|---|---|
| px | 屏幕物理像素单位。 |
| vp | 屏幕密度相关像素单位,根据屏幕像素密度转换为屏幕物理像素。 |
| fp | 字体像素,与vp类似适用于屏幕密度变化,随系统字体大小设置变化。 |
| lpx | 视窗逻辑像素单位,lpx单位为实际屏幕宽度与逻辑宽度(在 config.json 中配置的 designWidth )的比值,如配置 designWdith 为 720 时,在实际宽度为 1440 物理像素的屏幕上, 1px 为 2px 。 |
ArkUI开发框架也提供了全局方法把这些不同的尺寸单位相互转换,全局方法如下所示:
declare function vp2px(value: number): number;declare function px2vp(value: number): number;declare function fp2px(value: number): number;declare function px2fp(value: number): number;declare function lpx2px(value: number): number;declare function px2lpx(value: number): number;提供其他单位与px单位互相转换的方法。
| 接口 | 描述 |
|---|---|
| vp2px(value : number) : number | 将vp单位的数值转换为以px为单位的数值。 |
| px2vp(value : number) : number | 将px单位的数值转换为以vp为单位的数值。 |
| fp2px(value : number) : number | 将fp单位的数值转换为以px为单位的数值。 |
| px2fp(value : number) : number | 将px单位的数值转换为以fp为单位的数值。 |
| lpx2px(value : number) : number | 将lpx单位的数值转换为以px为单位的数值。 |
| px2lpx(value : number) : number | 将px单位的数值转换为以lpx为单位的数值。 |
最后我们通过代码来体验一下
/* * Copyright (c) 2021 JianGuo Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */@[email protected] Example { build() { Column() { Column() { Text("width(220)") .width(220).height(40).backgroundColor(0xF9CF93) .textAlign(TextAlign.Center).fontColor(Color.White).fontSize('12vp') }.margin(5) Column() { Text("width('220px')") .width('220px').height(40).backgroundColor(0xF9CF93) .textAlign(TextAlign.Center).fontColor(Color.White) }.margin(5) Column() { Text("width('220vp')") .width('220vp').height(40).backgroundColor(0xF9CF93) .textAlign(TextAlign.Center).fontColor(Color.White).fontSize('12vp') }.margin(5) Column() { Text("width('220lpx') designWidth:720") .width('220lpx').height(40).backgroundColor(0xF9CF93) .textAlign(TextAlign.Center).fontColor(Color.White).fontSize('12vp') }.margin(5) Column() { Text("width(vp2px(220) + 'px')") .width(vp2px(220) + 'px').height(40).backgroundColor(0xF9CF93) .textAlign(TextAlign.Center).fontColor(Color.White).fontSize('12vp') }.margin(5) Column() { Text("fontSize('12fp')") .width(220).height(40).backgroundColor(0xF9CF93) .textAlign(TextAlign.Center).fontColor(Color.White).fontSize('12fp') }.margin(5) }.width('100%').height("100%").justifyContent(FlexAlign.Center) }}
参考文档
边栏推荐
- LeetCode高频题73. 矩阵置零
- Do wealth management products only see the principal but not the income?
- 十分钟教会你如何使用VitePress搭建及部署个人博客站点
- 期货开户欲善其事先利其器
- Xingyun Butler won the "2022 Outstanding Brand Image Award" at the 11th China Finance Summit
- day8·函数封装
- 2022-08-02~04 Group 4 Self-cultivation class study notes (every day)
- SQL中COUNT和SUM
- 华为设备Smart Link和Monitor Link配置命令
- -ST表模板
猜你喜欢

配置网络源仓库

期货开户流程简便网上可办

LeetCode Question of the Day (1706. Where Will the Ball Fall)

Cholesterol-PEG-Thiol,CLS-PEG-SH,胆固醇-聚乙二醇-巯基改善胆固醇溶解度

【Endnote】插入文献时,自动弹出select matching reference

选择排名靠前的期货公司开户

ByteDance Flink Status Query Practice and Optimization

The power behind | Open up a new experience of intelligent teaching Huayun Data helps Tianchang Industrial School to build a new IT training room

深度学习之 11 残差网络的实现

MAUI Blazor 权限经验分享 (定位,使用相机)
随机推荐
【CC3200AI 实验教程2】疯壳·AI语音人脸识别(会议记录仪/人脸打卡机)-系统测试
王爽汇编语言第五章:【BX】和loop指令
使用 Redis 源码编译发布 Windows 版 Redis For Windows 发行包
mmap kernel implementation and physical memory organization
2022-08-04 Brighthouse: An Analytic DataWarehouse for Ad-hoc Queries
Synchronized锁升级
块分配器SLAB的内核实现
7.nodejs--egg框架简介、以及get、post请求
Stack和Queue 栈和队列
2022-08-03 顾宇佳 学习笔记
特种期货开户交易权限开通认定标准
‘proxy‘ config is set properly,see“npm help config“
FOF投资组合表现跟进(截止至2022.7.22)
day8·函数封装
美团二面:为什么Redis会有哨兵?
2022-08-02~04 Group 4 Self-cultivation class study notes (every day)
Qt实现多国语言切换
Stuck at sill idealTree buildDeps when npm install
SQL中COUNT和SUM
DSPE-PEG-Azide,DSPE-PEG-N3,磷脂-聚乙二醇-叠氮具有亲水和疏水性