如何在Jetpack Compose的LazyRow中创建自定义滚动。

huangapple go评论50阅读模式
英文:

How to make a customized scroll in LazyRow Jetpack Compose

问题

我正在使用Jetpack Compose制作Trello应用程序的克隆版。其中有一个屏幕,显示了面板中的所有列表,并以一行的方式展示,我已经使用lazyRow来实现这个功能。

在原始的Trello应用程序中,当滚动列表时,我注意到的一个区别是,下一个项目会在屏幕的正中间准确停止,即使我们以更快的速度滚动,也不会跳过任何项目。

然而,在我的克隆应用程序中的LazyRow中,滚动行为只取决于我们滚动的速度。

我想知道我们是否可以在LazyRow中实现类似Trello的滚动功能。

英文:

I am making a trello application clone in jetpack compose. In which there is a screen where all the lists in the board are displayed in a row , I have used lazyRow to implement that.
One difference I saw when scrolling the lists in the original trello app was that while scrolling the next item would stop exactly at the middle of the screen and it also doesn't skip any item even if we scroll with more speed.

Whereas in the LazyRow in my clone application the scroll behavoiur just depends on the power of our scroll.

I wanted to know if we could implement the trello like scrolling functionality in LazyRow.

答案1

得分: 1

Yes, you can use SnapFlingBehavior for that. You can have a look at the HorizontalPager implementation to see how it is used - it is a wrapper for LazyRow which is using SnapFlingBehavior. Depending on what exactly you need, you might be even able to simply replace your LazyRow with HorizontalPager and use different pageSize than the default PageSize.Fill.

英文:

Yes, you can use SnapFlingBehavior for that. You can have a look at the HorizontalPager implementation to see how it is used - it is a wrapper for LazyRow which is using SnapFlingBehavior. Depending on what exactly you need, you might be even able to simply replace your LazyRow with HorizontalPager and use different pageSize than the default PageSize.Fill.

huangapple
  • 本文由 发表于 2023年5月24日 20:33:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定