gpt4 book ai didi

android - RecycleView 的 setInitialPrefetchItemCount 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 13:10:22 25 4
gpt4 key购买 nike

我试图通过使用支持库 25.1 中引入的新 API 提前预取 View 来改善用户体验,同时滚动图像网格来控制 RecycleView 中预取项目的数量。

GridLayoutManager layoutManager = new GridLayoutManager(this.getContext(), PhotoGridViewHolder.SPAN_SIZE);
layoutManager.setItemPrefetchEnabled(true);
layoutManager.setInitialPrefetchItemCount(30);
photosRecycleView.setLayoutManager(layoutManager);
... add 100 photos to the adapter ...

我还为我的 ViewHolder 添加了日志记录,这样我就可以查看绑定(bind)是否真的发生了。

void bind(final Photo photo, int position) {
// I expcet to see 30 logs without event scrolling as the intial set to 30.
log.d("binding photo: " + photo.getId());
loadPhoto(photo);
}

但是,它似乎不起作用,因为我加载了一个包含 100 张图像的列表,但我只看到了几个日志条目(仅获取可见项目),但我希望在 30 处看到,因为我将其设置为像这样。

最佳答案

正如@FlanschiFox 和他的回答下方的评论所说,这仅适用于内部 RecyclerView。另外,我写了一个 PreloadLinearLayoutManager here在列表滚动到末尾之前预加载数据 5 项。它可能会对您有所帮助。

关于android - RecycleView 的 setInitialPrefetchItemCount 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46958484/

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