像素

px

屏幕物理像素,屏幕像素点(发光点)

1window.innerWidth
window.innerWidth

vp

设置盒子大小,根据屏幕像素密度,转为屏幕物理密度,默认单位vp,1vp=3px

fp

设置字体大小,跟随系统字体大小变化

lpx

逻辑像素单位,1lpx=2px

转换

 1@Entry  2@Component  3struct Page02_TaskList {  4 build() {  5 Column() {  6 Text('文本')  7 .fontSize(10)  8 .width(vp2px(100) + "px")  9 .height(100) 10 .backgroundColor("red") 11 12 Text('文本') 13 .fontSize(10) 14 .width('300px') 15 .height('300px') 16 .backgroundColor("blue") 17 18 Text('文本') 19 .fontSize(10) 20 .width('200lpx') 21 .height('200lpx') 22 .backgroundColor("black") 23 24 } 25 .height('100%') 26 .width('100%') 27 } 28}
@Entry @Component struct Page02_TaskList { build() { Column() { Text('文本') .fontSize(10) .width(vp2px(100) + "px") .height(100) .backgroundColor("red") Text('文本') .fontSize(10) .width('300px') .height('300px') .backgroundColor("blue") Text('文本') .fontSize(10) .width('200lpx') .height('200lpx') .backgroundColor("black") } .height('100%') .width('100%') } }

Powered By 可尔物语

浙ICP备11005866号-12