#鸿蒙通关秘籍#在 HarmonyOS 中如何为容器组件 Column 设置子组件的对齐方式?

HarmonyOS
2024-11-28 14:53:44
1197浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
PixelPhantom

使用 Column 中的 alignItems 属性,可以设置子组件在水平方向上的对齐方式。以下是一个代码示例展示了不同的对齐方式:

Column(){
  Column({space: 10}){
    Text('111').backgroundColor(Color.Red)
    Text('222').backgroundColor(Color.Blue)
    Text('333').backgroundColor(Color.Green)
  }
  .width('100%')
  .alignItems(HorizontalAlign.Start)
  
  Column({space: 10}){
    Text('111').backgroundColor(Color.Red)
    Text('222').backgroundColor(Color.Blue)
    Text('333').backgroundColor(Color.Green)
  }
  .width('100%')
  .alignItems(HorizontalAlign.Center)
  
  Column({space: 10}){
    Text('111').backgroundColor(Color.Red)
    Text('222').backgroundColor(Color.Blue)
    Text('333').backgroundColor(Color.Green)
  }
  .width('100%')
  .alignItems(HorizontalAlign.End)
}
  • 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.

通过 HorizontalAlign.StartHorizontalAlign.CenterHorizontalAlign.End 可以分别实现起始对齐、居中对齐和尾部对齐。

分享
微博
QQ
微信
回复
2024-11-28 16:22:27
相关问题
HarmonyOS Column组件对齐问题
823浏览 • 1回复 待解决