HarmonyOS RelativeContainer宽高设置问题?

RelativeContainer内部若存在一组件设置了‘顶部对齐容器顶部,底部对齐容器底部’,就会使这个RelativeContainer的height变成‘100%’的效果,手动设置‘auto’无效。这种内部子组件宽高不确定的情况,只能手动计算宽高,有没有更好的解决办法。

@Entry
@Component
export struct RelativeDemo {

  build() {
    Column(){
      RelativeContainer(){
        Row()
          .alignRules({
            top: { anchor: '__container__', align: VerticalAlign.Top },
            bottom: { anchor: '__container__', align: VerticalAlign.Bottom }
          })
          .width(50)
          .backgroundColor(Color.Green)
      }.backgroundColor(Color.Red)
      .height('auto')
    }
    .height('100%')
    .width('100%')
    .backgroundColor(Color.Blue)
  }
}
阅读 392
1 个回答

设置了.height('auto')完全没有必要再设置顶部对齐容器顶部,底部对齐容器底部。这两个本身就是冲突的。auto是让父布局去设配子组件的高度。alignRules是让子组件适配父布局的高度

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进