Reputation: 11
I'm trying to inflate all items in RecyclerView
, My code is not working on devices below API 24
, here is my code.
This is my PreCachingLayoutManager
class which extends 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;
}
}
This is my activity code
dealsImagesRecyclerView =
findViewById(R.id.dealsImagesRecyclerView);
layoutManager = new
PreCachingLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
layoutManager.setExtraLayoutSpace(deviceHeight);
layoutManager.setItemPrefetchEnabled(true);
dealsImagesRecyclerView.setLayoutManager(layoutManager);
Upvotes: 1
Views: 2138
Reputation: 64
RecycleView is created to optimize the load, to not inflate unnecessary itens.
If you wanna inflate all itens, maybe you should use listview.
Upvotes: 3