SmartRefreshLayout
SmartRefreshLayout copied to clipboard
用classic的header和footer模拟微信消息列表(默认不能加载更多,可以下拉加载历史数据),当历史数据加载完毕,禁用下拉刷新,会导致列表滑动冲突
val srl = view.findViewById<SmartRefreshLayout>(R.id.srl) val recycler = view.findViewById<RecyclerView>(R.id.recycler)
srl.setEnableLoadMore(false)
srl.setOnRefreshListener {
val list = ArrayList<Int>()
for (index in 100..110) {
list.add(index)
}
adapter.addData(0, list)
srl.finishRefresh()
if (adapter.list.size >= 50) {
srl.setEnableRefresh(false)
}
}
val list = ArrayList<Int>()
for (index in 1..10) {
list.add(index)
}
recycler.layoutManager = LinearLayoutManager(activity)
adapter = activity?.let { MessageSystemListAdapter(it, list) }!!
recycler.adapter = adapter
xml
<com.scwang.smart.refresh.layout.SmartRefreshLayout android:id="@+id/srl" android:layout_width="match_parent" android:layout_height="match_parent">
<com.scwang.smart.refresh.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.scwang.smart.refresh.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
禁用下拉刷新的代码 不要立即执行,给一个延时执行,建议1秒的延时,具体也可以自己调试选择合适的延时时间
+1 使用 setEnableRefresh(false) 遇到同样场景问题,增加延迟后已解决
延迟不稳定,下拉后快速滑动到顶部还是会触发的
@scwang90 延迟1秒后,滑动还是有问题