HarmonyOS 组件布局间距问题?

stack布局或column布局,如何设置某个组件距离顶部的间距而不是上一个组件的margin?

举个例子,column布局,有的组件间距较大,根据UI设计稿,想设置某个组件直接距离父组件顶部的间距,而不是上一个组件底部的间距,这种如何设置呢?

阅读 536
1 个回答

可以设置margin的top,即可解决您的问题,下面demo中的第二个row取10、500,分别跑了一下,效果显著,您可以看一下:

@Entry
@Component
struct MarginPage {
  @State message: string = 'Hello World';
  build() {
   Column(){
      Row(){}.height(100).width('100%').backgroundColor(Color.Red)
     // .margin({top:10})
      .margin({top:100})
     Row(){}.height(100).width('100%').backgroundColor(Color.Red)
     // .margin({top:10})
     .margin({top:500})
   }
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进