HarmonyOS List组件contentStartOffset属性不生效?

如题:HarmonyOS List组件contentStartOffset属性不生效?

阅读 530
1 个回答

可以使用替代方案在List外面要嵌套Row组件,不要直接把List做根组件。示例参考如下:

@Entry
@Component
struct ListLanesExample {
  @State arr: string[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8",]
  @State alignListItem: ListItemAlign = ListItemAlign.Center
  build() {
    Row() {
      List({ space: 8 }) {
        ForEach(this.arr, (item: string) => {
          ListItem() {
            Text('' + item)
              .width(80)
              .height(30)
              .fontSize(16)
              .textAlign(TextAlign.Center)
              .borderRadius(10)
              .backgroundColor(0xFFFFFF)
          }
          .border({ width: 2, color: Color.Green })
        }, (item: string) => item)
      }
      .height('100%')
      .layoutWeight(1)
      .listDirection(Axis.Horizontal)
      .border({ width: 3, color: Color.Red })
      .alignListItem(this.alignListItem)
      .scrollBar(BarState.Off)
      .contentStartOffset(20)
    }
    .height(64)
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进