在HarmonyOS NEXT开发中如何使Text组件填充满父组件?
build() {
Row() {
Row() {
Text(this.str)
.constraintSize({ maxWidth: '100%', minHeight: "30vp" })
.backgroundColor(Color.Gray)
.fontSize('24vp')
}
.key('row1')
.constraintSize({ maxWidth: '100%'})
.backgroundColor(Color.Green)
}
.key('row2')
.backgroundColor(Color.Yellow)
.width('90%')
Button('add')
.onClick(() => {
this.str += 'hello';
})
Button('reset')
.onClick(() => {
this.str = 'hello';
})
}
想让row1组件的大小随Text组件的大小变化,当最外层row2宽度放不下时,自动换行,并且完全填充row2容器,但目前在row1外侧总有一段无法被填充的,如何修改可以使row1/Text完全填充row2?
把row2的width去掉就好了,如果需要调节布局可以使用margin。
