[英]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.