gpt4 book ai didi

android - 我们如何检测到当前 View 由于滚动而超出可见范围?

转载 作者:行者123 更新时间:2023-11-29 23:39:07 24 4
gpt4 key购买 nike

对于回收站 View ,支架模式用于提高效率。
当我们滚动回收站列表时,将创建或重用 View 中显示的项目。
我的问题是:如果一个项目被滚动出可见性并且相应的 View 不可见,是否有任何调用的方法表明这一点?例如。如果我们正在 View 中下载资源并且我们需要在用户 ScrollView 时取消下载,这是自动完成的还是我们需要在 ViewHolder 或其他东西上实现一些方法调用?

最佳答案

您可以覆盖此 RecyclerView 方法来检查项目何时被回收。

    @Override 
public void onViewRecycled(RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);
// check if download is in progress and stop it.
}

Called when a view created by this adapter has been recycled.

A view is recycled when a RecyclerView.LayoutManager decides that it no longer needs to be attached to its parent RecyclerView. This can be because it has fallen out of visibility or a set of cached views represented by views still attached to the parent RecyclerView. If an item view has large or expensive data bound to it such as large bitmaps, this may be a good place to release those resources.

RecyclerView calls this method right before clearing ViewHolder's internal data and sending it to RecycledViewPool. This way, if ViewHolder was holding valid information before being recycled, you can call getAdapterPosition() to get its adapter position.

关于android - 我们如何检测到当前 View 由于滚动而超出可见范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52019530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com