如何检查滚动位置是在ListView的顶部还是底部? [英] How to check if scroll position is at top or bottom in ListView?

查看:68
本文介绍了如何检查滚动位置是在ListView的顶部还是底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现无限滚动功能.

我尝试在NotificationListener上使用内部的ListView来检测Scroll事件,但是看不到表明滚动是否到达视图底部的事件.

I tried using a ListView inside on a NotificationListener to detect Scroll events, but I can't see an event that says if the scroll has reached the bottom of the view.

哪种方法是实现这一目标的最佳方法?

Which would be the best way to achieve this?

推荐答案

您可以使用ListView.builder创建具有无限项的滚动列表.当显示新单元格时,将根据需要调用您的itemBuilder.

You can use a ListView.builder to create a scrolling list with unlimited items. Your itemBuilder will be called as needed when new cells are revealed.

如果希望收到有关滚动事件的通知,以便可以从网络上加载更多数据,则可以传递controller自变量,并使用addListener将侦听器附加到ScrollController. ScrollControllerposition可用于确定滚动是否接近底部.

If you want to be notified about scroll events so you can load more data off the network, you can pass a controller argument and use addListener to attach a listener to the ScrollController. The position of the ScrollController can be used to determine whether the scrolling is close to the bottom.

这篇关于如何检查滚动位置是在ListView的顶部还是底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆