HarmonyOS RelativeContainer自适应高度相关

RelativeContainer不设置height后发现高度是全屏,需要设置什么属性才能自适应子组件的高度?

HarmonyOS
2024-12-20 16:03:52
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

RelativeContainer支持宽高自适应子组件,将其设置为auto即可,但限制是当width设置auto时,如果水平方向上子组件以容器作为锚点,则auto不生效,垂直方向上同理,具体使用方法请参考文档。文档链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-relativecontainer-V5

请参考以下demo:

@Entry
@Component
struct MyRelativeContainer {
  build() {
    Column() {
      Row() {
        Text('宽度高度自适应')
      }
      .width("100%");
      RelativeContainer() {
        Row()
          .width(100)
          .height(100)
          .backgroundColor("#FF3333")
          .alignRules({})
          .id("row1")
        Row()
          .width(100)
          .height(100)
          .backgroundColor("#FFCC00")
          .alignRules({
            top: { anchor: "row1", align: VerticalAlign.Top },
            left: { anchor: "row1", align: HorizontalAlign.End },
          })
          .id("row2")
        Row()
          .height(100)
          .width(100)
          .backgroundColor("#FF6633")
          .alignRules({
            left: { anchor: "row1", align: HorizontalAlign.Start },
            top: { anchor: "row1", align: VerticalAlign.Bottom }
          })
          .id("row3")
      }
      .width("auto")
      .height("auto")
      .margin({ left: 50 })
      .border({ width: 2, color: "#6699FF" })
    }
    .height('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-20 19:23:53
相关问题
HarmonyOS RelativeContainer无法自适应高度
817浏览 • 1回复 待解决
HarmonyOS 高度自适应
659浏览 • 1回复 待解决
HarmonyOS RichText自适应高度
370浏览 • 1回复 待解决
HarmonyOS RelativeContainer宽高自适应问题
1195浏览 • 1回复 待解决
HarmonyOS webview高度不能自适应
227浏览 • 1回复 待解决
HarmonyOS RichText能否自适应高度
300浏览 • 1回复 待解决
HarmonyOS Web高度自适应问题
1152浏览 • 1回复 待解决
HarmonyOS web的高度自适应内容的高度
610浏览 • 1回复 待解决
HarmonyOS List高度根据内容自适应
503浏览 • 1回复 待解决
HarmonyOS Grid高度根据内容自适应
406浏览 • 1回复 待解决
HarmonyOS GridItem自适应高度问题
701浏览 • 1回复 待解决
HarmonyOS 高度自适应的问题
658浏览 • 1回复 待解决
HarmonyOS 如何实现自适应web的高度
231浏览 • 1回复 待解决
HarmonyOS Grid自适应高度和拖拽问题
925浏览 • 1回复 待解决
HarmonyOS List是否可以设置自适应高度
203浏览 • 1回复 待解决
HarmonyOS web组件怎么自适应高度
372浏览 • 1回复 待解决
HarmonyOS 自适应父组件高度问题
1440浏览 • 1回复 待解决
HarmonyOS Grid组件能否高度自适应
350浏览 • 1回复 待解决