HarmonyOS RelativeContainer组件的使用

在List组件中的item 使用RelativeContainer组件 的高度设置为 auto 还是一条占一屏高度,如何让高度根据子空间的高度自适应

HarmonyOS
2024-12-25 07:11:35
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

可以参考此demo如下:

@Entry
@Component
struct Index {

  build() {
    List() {
      ListItem() {
        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')
        }

        .height('auto')
        .margin({
          left: 50
        })
        .border({
          width: 2,
          color: '#6699FF'
        })
      }

      ListItem() {
        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')
        }

        .height('auto')
        .margin({
          left: 50
        })
        .border({
          width: 2,
          color: '#6699FF'
        })
      }

      ListItem() {
        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')
        }

        .height('auto')
        .margin({
          left: 50
        })
        .border({
          width: 2,
          color: '#6699FF'
        })
      }
    }
    .backgroundColor('#FFF1F3F5')
    .alignListItem(ListItemAlign.Center)
  }
}
  • 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.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
分享
微博
QQ
微信
回复
2024-12-25 10:08:17
相关问题
RelativeContainer 组件使用
1051浏览 • 1回复 待解决
HarmonyOS RelativeContainer使用问题
512浏览 • 1回复 待解决
HarmonyOS RelativeContainer组件
468浏览 • 1回复 待解决
HarmonyOS RelativeContainer 组件咨询
994浏览 • 1回复 待解决
RelativeContainer组件auto对齐规则
829浏览 • 1回复 待解决
HarmonyOS RelativeContainer居中问题
1256浏览 • 1回复 待解决
HarmonyOS RelativeContainer控件不显示
599浏览 • 1回复 待解决
HarmonyOS RelativeContainer相关问题
728浏览 • 1回复 待解决