像素

vp

虚拟像素,vp2px(100),vp转px,保证不同设备视觉一致

背景

 1@Entry  2@Component  3struct Index {  4 build() {  5 RelativeContainer() {  6 Column({  7 space: 10  8 }) {  9 Row({ space: 10 }) { 10 Text('正圆') 11 .padding('30vp') 12 .backgroundColor(Color.Gray) 13 .backgroundImage($r('app.media.startIcon')) 14 .backgroundImagePosition({ 15 x: vp2px(10), 16 y: vp2px(10) 17 }) 18 .width('100vp') 19 .height('100vp') 20 } 21 }.padding(15) 22 } 23 } 24}
@Entry @Component struct Index { build() { RelativeContainer() { Column({ space: 10 }) { Row({ space: 10 }) { Text('正圆') .padding('30vp') .backgroundColor(Color.Gray) .backgroundImage($r('app.media.startIcon')) .backgroundImagePosition({ x: vp2px(10), y: vp2px(10) }) .width('100vp') .height('100vp') } }.padding(15) } } }

缩放

 1@Entry  2@Component  3struct Index {  4 build() {  5 RelativeContainer() {  6 Column({  7 space: 10  8 }) {  9 Row({ space: 10 }) { 10 Text('正圆') 11 .backgroundColor(Color.Gray) 12 .backgroundImage($r('app.media.bird')) 13 .backgroundImageSize(ImageSize.Cover) 14 .width('100vp') 15 .height('100vp') 16 17 Text('正圆') 18 .backgroundColor(Color.Gray) 19 .backgroundImage($r('app.media.bird')) 20 .backgroundImageSize(ImageSize.Contain) 21 .width('200vp') 22 .height('100vp') 23 } 24 25 Text('正圆') 26 .backgroundColor(Color.Gray) 27 .backgroundImage($r('app.media.bird')) 28 .backgroundImageSize({ 29 width:130, 30 height:100 31 }) 32 .width('200vp') 33 .height('100vp') 34 }.padding(15) 35 } 36 } 37}
@Entry @Component struct Index { build() { RelativeContainer() { Column({ space: 10 }) { Row({ space: 10 }) { Text('正圆') .backgroundColor(Color.Gray) .backgroundImage($r('app.media.bird')) .backgroundImageSize(ImageSize.Cover) .width('100vp') .height('100vp') Text('正圆') .backgroundColor(Color.Gray) .backgroundImage($r('app.media.bird')) .backgroundImageSize(ImageSize.Contain) .width('200vp') .height('100vp') } Text('正圆') .backgroundColor(Color.Gray) .backgroundImage($r('app.media.bird')) .backgroundImageSize({ width:130, height:100 }) .width('200vp') .height('100vp') }.padding(15) } } }

Powered By 可尔物语

浙ICP备11005866号-12