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%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
分享
微博
QQ
微信
回复
2024-12-20 19:23:53
相关问题
HarmonyOS RelativeContainer无法自适应高度
1288浏览 • 1回复 待解决
HarmonyOS 高度自适应
1087浏览 • 1回复 待解决
HarmonyOS RelativeContainer 不能自适应宽高
1090浏览 • 1回复 待解决
HarmonyOS RelativeContainer宽高自适应问题
1711浏览 • 1回复 待解决
HarmonyOS RichText自适应高度
786浏览 • 1回复 待解决
HarmonyOS GridItem自适应高度问题
1108浏览 • 1回复 待解决
HarmonyOS 高度自适应的问题
1089浏览 • 1回复 待解决
HarmonyOS Web高度自适应问题
1657浏览 • 1回复 待解决
HarmonyOS RichText能否自适应高度
664浏览 • 1回复 待解决
HarmonyOS webview高度不能自适应
698浏览 • 1回复 待解决
HarmonyOS web的高度自适应内容的高度
1236浏览 • 1回复 待解决
HarmonyOS web组件自适应高度问题
1827浏览 • 1回复 待解决
HarmonyOS Grid组件能否高度自适应
789浏览 • 1回复 待解决
HarmonyOS 自适应父组件高度问题
1899浏览 • 1回复 待解决
HarmonyOS web组件怎么自适应高度
795浏览 • 1回复 待解决
HarmonyOS List高度根据内容自适应
1059浏览 • 1回复 待解决
HarmonyOS Grid高度根据内容自适应
882浏览 • 1回复 待解决