Skip to content

Instantly share code, notes, and snippets.

@mohamedagamy
Created March 27, 2019 11:29
Show Gist options
  • Save mohamedagamy/51b62745be38093e358ea827cdff8fdc to your computer and use it in GitHub Desktop.
Save mohamedagamy/51b62745be38093e358ea827cdff8fdc to your computer and use it in GitHub Desktop.
//https://stackoverflow.com/questions/39374227/how-to-load-all-the-images-in-the-background-of-a-recyclerview-in-android
public class PreCachingLayoutManager extends LinearLayoutManager {
private static final int DEFAULT_EXTRA_LAYOUT_SPACE = 600;
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment