RelativeContainer无法根据子组件的高度,自适配自己的高度,详细代码
@Entry
@Component
export struct RelativeContainerDemo {
build() {
Column() {
RelativeContainer() {
Column() {
Text('13241234')
.fontColor('#333')
Text('234234234')
.fontColor('#333')
}
.alignRules({
left: {anchor: "__container__", align: HorizontalAlign.Start},
top: {anchor: "__container__", align: VerticalAlign.Top}
})
.id("Column2")
}
.width("auto").height("auto")
.backgroundColor(Color.Red)
Row().width('100%').height(40).backgroundColor(Color.Yellow)
}
.backgroundColor(Color.White)
.width('100%').height('100%')
}
}
从API 11开始,在RelativeContainer组件中,width、height设置auto可以自适应子组件。
但是当height设置auto时,如果垂直方向上子组件以容器作为锚点,则auto不生效,水平方向上同理。
相关规则参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-relativecontainer-V5