List滚动条时长时短,求解决方案?

List滚动条时长时短 。

@Entry 
@Component 
struct ListExample { 
  private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
  private arrItem: string[] = ["我是评论1", "我是评论2", "我是评论3", "我是评论4", 
    "我是评论5", "我是评论6"] 
  private arrItem2: string[] = ["我是评论1"] 
 
  @Builder 
  itemList(aa: number) { 
    List({ space: 20, initialIndex: 0 }) { 
      if (aa % 2 == 0) { 
        ForEach(this.arrItem, (item: string) => { 
          ListItem() { 
            Text('' + item) 
              .width('100%') 
              .height(50) 
              .fontSize(16) 
              .textAlign(TextAlign.Center) 
              .borderRadius(10) 
              .backgroundColor(0xFFFFFF) 
          } 
        }, (item: string) => item) 
      } else { 
        ForEach(this.arrItem2, (item: string) => { 
          ListItem() { 
            Text('' + item) 
              .width('100%') 
              .height(50) 
              .fontSize(16) 
              .textAlign(TextAlign.Center) 
              .borderRadius(10) 
              .backgroundColor(0xFFFFFF) 
          } 
        }, (item: string) => item) 
      } 
    } 
    .margin({ left: 20 }) 
    .listDirection(Axis.Vertical) 
    .scrollBar(BarState.Off) 
    .width('100%') 
  } 
 
  build() { 
    Column() { 
      List({ space: 20, initialIndex: 0 }) { 
        ForEach(this.arr, (item: number) => { 
          ListItem() { 
            Column({ space: 3 }) { 
              Text('' + item) 
                .width('100%') 
                .height(100) 
                .fontSize(16) 
                .textAlign(TextAlign.Center) 
                .borderRadius(10) 
                .backgroundColor(0xFFFFFF) 
              this.itemList(item) 
            } 
          } 
        }, (item: string) => item) 
      } 
      .listDirection(Axis.Vertical) 
      .scrollBar(BarState.On) 
      .friction(0.6) 
      .edgeEffect(EdgeEffect.Spring) 
      .width('90%') 
    } 
    .width('100%') 
    .height('100%') 
    .backgroundColor(0xDCDCDC) 
    .padding({ top: 5 }) 
  } 
}
HarmonyOS
2024-06-03 23:54:01
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
bho2000

这个当前List对自身内容的总高度是根据当前在屏幕内出现的ListItem经过估算得到的,如果ListItem之间的高度不是相对等高的,那么随着ListItem的滑入滑出屏幕,List估算的内容总高度就会产生波动,而滚动条又是根据这个总高度来计算自身的高度的,所以就会体现成在List滑动过程中滚动条的高度一直在产生变化。这个是当前List的实现规格导致的。

规避方案:最外层List改成Scroll。Scroll的内容总高度计算在滑动过程中是稳定的,因此可以保证滚动条不会出现类似List的这种时长时短。

分享
微博
QQ
微信
回复
2024-06-04 22:44:06
相关问题
如何获取List组件滚动条滚动的距离
771浏览 • 1回复 待解决
抓包应用,求解决方案
511浏览 • 1回复 待解决
请问ScrollView怎么显示滚动条
4079浏览 • 1回复 待解决
ListContainer 有滚动条 显示吗?
4433浏览 • 1回复 待解决
lazyforeach替换数据源解决方案
137浏览 • 1回复 待解决
图片存储解决方案谁知道啊?
1104浏览 • 1回复 待解决
webview中跨域问题解决方案
498浏览 • 1回复 待解决
Harmony API9之后 GIS 解决方案有哪些?
808浏览 • 1回复 待解决
list 支持循环滚动吗?
713浏览 • 1回复 待解决