相对布局 垂直方向居中问题反馈?

RelativeContainer布局中两个子组件,其中一个子组件需要相对另一个垂直方向上居中,设置了 center: { anchor: “xxx”, align: VerticalAlign.Center} 方式,但是失效

阅读 657
1 个回答

如下代码验证OK:

@Entry
@Component
export struct TextComponent {

  build() {
    Row() {
      RelativeContainer() {
        Image($r('app.media.startIcon'))
          .width(50)
          .id('view_1')
          .backgroundColor(Color.Red)
          .alignRules({
            center: { anchor: '__container__', align: VerticalAlign.Center },
            left: { anchor: '__container__', align: HorizontalAlign.Start }
          })
        Column() {
          Text('十三太保')
        }
        .width(80)
        .height(20)
        .id('view_2')
        .backgroundColor(Color.Green)
        .alignRules({
          center: { anchor: 'view_1', align: VerticalAlign.Center },
          left: { anchor: 'view_1', align: HorizontalAlign.End }
        })
      }
      .margin({left: 40})
      .backgroundColor(Color.Pink)
      .width(300)
      .height(300)
    }
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进