HarmonyOS 如何降低滑动速度?

用scroll + scrollSnap 实现一个 swiper 效果,左右滑动时轻轻一点就可以滑动很多页,有没有什么办法降低滑动灵敏度,可以一页一页的滑动。

阅读 482
1 个回答

可以设置friction摩擦系数减少灵敏度,见demo:

Scroll(this.scroller) {
  Row({ space: this.swiperOptions.itemSpace }) {
    ForEach(this.swiperDataList, (model: string, index: number) => {
      this.customContentBuilder(model, index)
    }, (model: string, index: number) => JSON.stringify(model) + index)
  }
}
.width('100%')
.scrollable(ScrollDirection.Horizontal)
.scrollBar(BarState.Off)
.enabled(true)
.align(Alignment.Start)
.edgeEffect(EdgeEffect.None)
.scrollSnap({
  snapPagination: this.swiperItemWidth + this.swiperOptions.itemSpace,
  snapAlign: ScrollSnapAlign.START
})
.friction(4) //设置摩擦系数,手动划动滚动区域时生效,只对惯性滚动过程有影响,数值越大摩擦越大,可自行适配

参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-scroll-V5\#friction10

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进