HarmonyOS GridItem之间有一条竖线

现在实现Grid控件每行有两个数据,这两个数据之间需要一条竖线分隔如何实现?

HarmonyOS
2025-01-09 16:04:44
491浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

目前Grid没有专门的一个分割线设置。可以通过给GridItem设置边框来实现分割效果或者尝试使用Divider分隔器组件来设置。

1.Divider分隔器组件:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-divider-V5

2.添加border

@Entry
@Component
struct ChangeGridHeight {
  build() {
    Column() {
      Grid() {
        ForEach([1, 2, 3, 4, 5], (item: number, index: number) => {
          GridItem() {
            Column() {
              Text(item.toString())
                .width('100%')
                .height('25%')
                .backgroundColor('#ccc')
                .borderColor(Color.Black)
                .borderWidth('2px')
            }
          }.border({
            width: {
              bottom: 5,
            },
            color: {
              bottom: Color.Red,
            },
            style: {
              bottom: BorderStyle.Solid,
            }
          })
          .width('100%')
        })
      }
      .columnsTemplate('1fr')
    }.height('100%')
    .width('100%')
  }
}
  • 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.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
分享
微博
QQ
微信
回复
2025-01-09 19:56:40


相关问题
HarmonyOS 如何绘制一条虚线
681浏览 • 1回复 待解决
恭喜您,今日已阅读两篇内容,特奖励+2声望, 快来领取吧。