Harmony 实现宽高等比
一行代码实现宽高等比
借助aspectRatio属性
aspectRatio: number指定当前组件的宽高比aspectRatio = width/height
js
build() {
Row() {
Row()
.width(100)
.backgroundColor(Color.Blue)
.aspectRatio(1)
Row()
.width(100)
.backgroundColor(Color.Red)
.aspectRatio(16 / 8)
}
.height('100%')
}aspectRatio的值可以是1宽高等比aspectRatio的值可以是16 / 9>>> 16 * 9的比例