在 HarmonyOS 中,GridCol 的 order 为什么没生效?

我写了个小例子,想让 B 显示在最前面:

GridRow({ columns: 3 }) {
  GridCol({ span: 1, order: 2 }) { Text("A") }
  GridCol({ span: 1, order: 1 }) { Text("B") }
  GridCol({ span: 1 }) { Text("C") }
}

结果顺序还是 A B C,这是为啥?

阅读 649
1 个回答

据我所知,order 的规则是:没设置 order 的会排在最前,然后按数值从小到大排。所以你例子里 C 没设置 order,它会排在最前,导致顺序是 C → B → A。正确效果可以这样写:

GridRow({ columns: 3 }) {
  GridCol({ span: 1, order: 2 }) { Text("A").backgroundColor(Color.Red) }
  GridCol({ span: 1, order: 1 }) { Text("B").backgroundColor(Color.Green) }
  GridCol({ span: 1, order: 3 }) { Text("C").backgroundColor(Color.Blue) }
}

这样顺序就是 B → A → C。