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);
RecycleView is created to optimize the load, to not inflate unnecessary itens.
If you wanna inflate all itens, maybe you should use listview.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.