Scroll组件如何通过代码的方式停止滚动

Scroll组件如何通过代码的方式停止滚动

HarmonyOS
2024-06-04 00:33:31
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
firecc

使用下面的demo可以解决该问题,当停止滚动的时候将另一个的scrollBy设置为0,0即可完成

@Entry 
@Component 
struct ScrollIndex { 
  scrollerTop: Scroller = new Scroller() 
  scrollerBottom: Scroller = new Scroller() 
  @State dataListTop: string[] = ["a", "b", 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', "l"] 
  @State dataListBottom: string[] = ["a", "b", 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', "l"] 
 
  build() { 
    Column() { 
      List({ space: 8, scroller: this.scrollerTop }) { 
        ForEach(this.dataListTop, (item: string) => { 
          ListItem() { 
            Row() { 
              Text("item" + item) 
            } 
            .alignItems(VerticalAlign.Center) 
            .width(100) 
            .justifyContent(FlexAlign.Center) 
            .backgroundColor(Color.Pink) 
            .borderRadius(5) 
            .height("100%") 
          }.height("100%") 
        }) 
      }.height(60).listDirection(Axis.Horizontal) 
      .scrollBar(BarState.Off) 
 
      Divider().color(Color.Red).height(10) 
 
      List({ space: 8, scroller: this.scrollerBottom }) { 
        ForEach(this.dataListBottom, (item: string) => { 
          ListItem() { 
            Row() { 
              Text("item" + item) 
            } 
            .alignItems(VerticalAlign.Center) 
            .width(100) 
            .justifyContent(FlexAlign.Center) 
            .backgroundColor(Color.Pink) 
            .borderRadius(5) 
            .height("100%") 
          }.height("100%") 
        }) 
      }.height(60).listDirection(Axis.Horizontal) 
      .scrollBar(BarState.Off) 
      .onScroll((offset: number, state: ScrollState) => { 
        this.scrollerTop.scrollBy(offset, 0) 
      }) 
    }.width("100%").height("100%") 
  } 
}
分享
微博
QQ
微信
回复
2024-06-04 23:07:48
相关问题
如何获取Scroll组件的当前滚动偏移量
570浏览 • 1回复 待解决
ArkUI如何通过代码动态创建组件
846浏览 • 1回复 待解决
如何获取List组件滚动滚动距离
785浏览 • 1回复 待解决
Scroll组件展示位置如何调整
708浏览 • 1回复 待解决
如何停止UIAbility自身
563浏览 • 1回复 待解决
如何通过代码触发APP重启
426浏览 • 1回复 待解决
Scroll初始时自动滚动一段距离
343浏览 • 1回复 待解决
Scroll组件内显示不全问题
334浏览 • 1回复 待解决
animateTo动画如何直接停止
764浏览 • 1回复 待解决
如何通过代码随意修改锁屏图片?
4017浏览 • 1回复 待解决
在嵌套组件Scroll不生效
639浏览 • 1回复 待解决