Rom*_*iri 5 android gridlayoutmanager android-recyclerview
我试图通过使用支持库 25.1 中引入的新 API 提前预取视图来提高用户在滚动图像网格时的体验,以控制 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 ...
Run Code Online (Sandbox Code Playgroud)
我还为我的 ViewHolders 添加了日志记录,以便我可以查看绑定是否真的发生了。
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);
}
Run Code Online (Sandbox Code Playgroud)
但是,它似乎不起作用,因为我加载了 100 张图像的列表,但我只看到了几个日志条目(只是获取了可见项目),但是我希望看到 30,因为我将它设置为这样.
根据文档,这仅适用于内部 RecyclerView。
设置在collectInitialPrefetchPositions(int, LayoutPrefetchRegistry)中预取的项目数,它定义了当此LayoutManager的RecyclerView嵌套在另一个RecyclerView中时应预取多少内部项目。
| 归档时间: |
|
| 查看次数: |
4648 次 |
| 最近记录: |