当前位置:网站首页>OpenHarmony Pixel Unit (eTS)
OpenHarmony Pixel Unit (eTS)
2022-08-05 14:16:00 【HUAWEI CLOUD】
ArkUIDevelopment framework provided 4 Pixel units for developers to use,分别是: px 、 vp 、 fp 和 lpx ,框架采用vpis the base data unit.它们之间的区别如下表所示:
| 名称 | 描述 |
|---|---|
| px | 屏幕物理像素单位. |
| vp | Screen density relative pixel unit,根据屏幕像素密度转换为屏幕物理像素. |
| fp | 字体像素,与vpSimilar applies to screen density changes,Varies with system font size setting. |
| lpx | Window logical pixel units,lpxThe unit is the actual screen width and the logical width(在 config.json 中配置的 designWidth )的比值,如配置 designWdith 为 720 时,在实际宽度为 1440 物理像素的屏幕上, 1px 为 2px . |
ArkUIThe development framework also provides global methods to convert these different size units to each other,The global method is shown below:
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;Other units available withpxThe method of converting units to each other.
| 接口 | 描述 |
|---|---|
| vp2px(value : number) : number | 将vpThe numerical value of the unit is converted to px为单位的数值. |
| px2vp(value : number) : number | 将pxThe numerical value of the unit is converted to vp为单位的数值. |
| fp2px(value : number) : number | 将fpThe numerical value of the unit is converted to px为单位的数值. |
| px2fp(value : number) : number | 将pxThe numerical value of the unit is converted to fp为单位的数值. |
| lpx2px(value : number) : number | 将lpxThe numerical value of the unit is converted to px为单位的数值. |
| px2lpx(value : number) : number | 将pxThe numerical value of the unit is converted to lpx为单位的数值. |
Finally, let's experience it through code
/* * 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) }}
参考文档
边栏推荐
- R语言ggplot2可视化:使用patchwork包将两个ggplot2可视化结果组合起来、使用labs函数为第两个子图都添加标题信息(subtitle for each subplots)
- 2022-08-02~04 Group 4 Self-cultivation class study notes (every day)
- day8·函数封装
- CVE-2021-37580 Apache ShenYu 身份验证绕过漏洞复现
- DevEco Studio配置:自定义头部代码注释
- LeetCode高频题70. 爬楼梯,青蛙跳台阶,暴力递归的尝试,改记忆化搜索和动态规划代码
- day7·拆包与装包
- 行云管家荣获第十一届中国财经峰会“2022杰出品牌形象奖”
- [vulhub]PostGresql远程代码执行漏洞复现(CVE-2018-1058)
- DSPE-PEG-Hydrazide,DSPE-PEG-HZ,磷脂-聚乙二醇-酰肼可增强稳定性
猜你喜欢

期货开户欲善其事先利其器

用户体验管理 - Managing user experience

开户的期货公司各有擅长的领域

特种期货开户交易权限开通认定标准

Stack和Queue 栈和队列

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

@2023 Graduate Candidates: How to Spend the "Golden Period" of Summer Research Exam Preparation

王爽汇编语言第五章:【BX】和loop指令

【深度强化学习】MAPPO 代码学习

Memory Management Architecture and Virtual Address Space Layout
随机推荐
Stack和Queue 栈和队列
C#员工考勤管理系统源码 考勤工资管理系统源码
CF1714A 题解
《ABP Framework 极速开发》教程首发
ByteDance Flink Status Query Practice and Optimization
内存问题难定位,那是因为你没用ASAN
伙伴分配器的内核实现
day14·私有化属性
期货开户流程简便网上可办
DSPE-PEG-Azide,DSPE-PEG-N3,磷脂-聚乙二醇-叠氮具有亲水和疏水性
国密是什么意思?属于商密还是普密?
Qt将图片保存为XML文件或者变为QSting
day6·动态导入模块
期货开户欲善其事先利其器
2022-08-04 clickhouse的join子句
The actual use of EOSJS in China Mobile Chain
期货开户公司的选择和作用
美团二面:为什么Redis会有哨兵?
What does state secret mean?Is it commercial secret or common secret?
更新数据到数据库和缓存的步骤