HarmonyOS list的divider bug

@Builder
listBuilder() {
  List({ scroller: this.scroller }) {
    ForEach(this.data, (item: TopicItem, index) => {
      ListItem() {
        Row() {
          RoundImageView({ imageUrl: item.imageUrl, defaultSize: 58, defaultRadius: 8 })
          Column() {
            Text(`#${item.name}`).fontSize(15)
            Text(`共${item.size}条动态`).fontSize(12).fontColor(default_gray100).margin({ top: 6 })
          }.layoutWeight(1).margin({ left: 12, right: 12 }).alignItems(HorizontalAlign.Start)

          Image($r('app.media.icon_next')).width(18).aspectRatio(1)
        }
        .height(70)
        .backgroundColor(white)
        .width("100%")
        .padding({ left: 12, right: 12 })
        .onClick(() => {
          setTimeout(() => {
            this.pathStack?.pop(item)
          }, 100)
        })
      }
    })
  }
  .divider({ strokeWidth: 0.4, color: default_gray100 })
  .edgeEffect(EdgeEffect.None)
  .scrollBarWidth(0)
  .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.

出现的列表中间隔没有了分割线。

HarmonyOS
2025-01-09 15:54:47
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

参考示例如下:

@Entry
@Component
struct ListDividePage {
  @State message: string = 'Hello World';
  scroller: Scroller = new Scroller()
  @State dataSource: Array<ListItemModel> = new Array()

  aboutToAppear(): void {
    let index = 0;
    while (index < 50) {
      this.dataSource.push({ "title": index.toString(), "showLine": index % 2 == 0 })
      index++
    }
  }

  build() {
    Column() {
      List({ scroller: this.scroller }) {
        ForEach(this.dataSource, (item: ListItemModel) => {
          ListItem() {
            ListItemView({ item: item })
          }
        }, (item: ListItemModel) => item.title)
      }.scrollBar(BarState.Off)

    }
    .backgroundColor('#0D182431')
    .width('100%')
    .height('100%')
  }
}

@Component
struct ListItemView {
  item: ListItemModel = new ListItemModel();

  build() {
    Column() {
      Text("item" + this.item.title)
        .fontSize(16)
        .fontColor(Color.Black)
        .height(80)
        .width("100%")
        .textAlign(TextAlign.Center)
        .backgroundColor(Color.White)
      // if (this.item.showLine){
      Divider().strokeWidth(1).color(Color.Red)
      // }
    }
    .width("100%")
    .height(81)
    .borderRadius(10)
    .backgroundColor(Color.White)
    .justifyContent(FlexAlign.SpaceBetween)
  }
}

class ListItemModel {
  constructor() {
  }

  title: string = ""
  showLine: boolean = false
}
  • 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.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
分享
微博
QQ
微信
回复
2025-01-09 19:14:57
相关问题
HarmonyOS Listdivider使用
1140浏览 • 0回复 待解决
List组件divider颜色显示透List组件颜色
824浏览 • 0回复 待解决
HarmonyOS getInspectorByKeybug
1359浏览 • 1回复 待解决
HarmonyOS Divider组件,如何能显示虚线
815浏览 • 1回复 待解决
Divider组件是否存在虚线属性
1653浏览 • 1回复 待解决
Divider组件如何设置分割线宽度
3693浏览 • 1回复 待解决
<state-container>貌似有BUG怎么处理?
5656浏览 • 1回复 待解决
HarmonyOS List嵌套list布局
924浏览 • 1回复 待解决
HarmonyOS List嵌套ListList嵌套Grid问题
935浏览 • 1回复 待解决
HarmonyOS 使用List警告
996浏览 • 1回复 待解决
HarmonyOS Listspace问题
884浏览 • 1回复 待解决
ArkTS UIList和集合List冲突问题
1316浏览 • 1回复 待解决