鸿蒙RelativeContainer定位


   RelativeContainer() {
        Line()
          .width("100%")
          .height(20)
          .margin({ top: 100 })
          .backgroundColor("#ff0000")
          .alignRules({
            top: {
              anchor: "__container__", align: VerticalAlign.Top,
            },
          })
          .id("a1")
        Text("我是中间测试")
          .width("100%")
          .backgroundColor("#00ff00")
          .alignRules({
            top: {
              anchor: "a1", align: VerticalAlign.Bottom,
            }, bottom: {
              anchor: "a2", align: VerticalAlign.Top,
            },
          })

        Line()
          .width("100%")
          .height(20)
          .margin({ bottom: 100 })
          .backgroundColor("#ff0000")
          .alignRules({
            bottom: {
              anchor: "__container__", align: VerticalAlign.Bottom,
            },
          })
          .id("a2")

      }
      .height('100%')
      .width('100%').backgroundColor(Color.White)
image.png

// 设置固定height(100) 在a1 和a2中间


image.png

//设置height("auto") 自动适应大小居中


image.png

//height("100%")全屏大小


image.png

//不设置 height 在a1 和a2中间充满

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容