[英]How to load all items in recyclerView at once?
我正在尝试在RecyclerView
中RecyclerView
所有项目,我的代码在API 24
以下的设备上无法正常工作,这是我的代码。
这是我的PreCachingLayoutManager
类,它扩展了LinearLayoutManager
。
public class PreCachingLayoutManager extends LinearLayoutManager {
private static final int DEFAULT_EXTRA_LAYOUT_SPACE = 800;
private int extraLayoutSpace = -1;
private Context context;
public PreCachingLayoutManager(Context context) {
super(context);
this.context = context;
}
public PreCachingLayoutManager(Context context, int extraLayoutSpace) {
super(context);
this.context = context;
this.extraLayoutSpace = extraLayoutSpace;
}
public PreCachingLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
this.context = context;
}
public void setExtraLayoutSpace(int extraLayoutSpace) {
this.extraLayoutSpace = extraLayoutSpace;
}
@Override
protected int getExtraLayoutSpace(RecyclerView.State state) {
if (extraLayoutSpace > 0) {
return extraLayoutSpace;
}
return DEFAULT_EXTRA_LAYOUT_SPACE;
}
}
这是我的活动代码
dealsImagesRecyclerView =
findViewById(R.id.dealsImagesRecyclerView);
layoutManager = new
PreCachingLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
layoutManager.setExtraLayoutSpace(deviceHeight);
layoutManager.setItemPrefetchEnabled(true);
dealsImagesRecyclerView.setLayoutManager(layoutManager);
创建RecycleView是为了优化负载,而不是增加不必要的Iten。
如果您想对所有iten进行充气,也许您应该使用listview。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.