You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.
I have the following code to collect my items to show in my RV:
// Spanned
public RecyclerView.LayoutManager getLayoutManager() {
if (!mMainView || mDataHolder.getViewMode(mActivity).equals("grid")) { // We force the grid view in subset
final Integer numColumns = UserPreferencesHandler.<Integer>readValue(mActivity, UserPreferencesHandler.PREF_KEY_NUM_COLUMNS);
SpannedGridLayoutManager layoutManager = new SpannedGridLayoutManager(SpannedGridLayoutManager.Orientation.VERTICAL, numColumns);
layoutManager.setSpanSizeLookup(new SpannedGridLayoutManager.SpanSizeLookup(position -> {
try {
switch (RVAdapterTimeline.this.getItemViewType(position)) {
case RVAdapter.VIEW_TYPE_HEADER:
try {
return new SpanSize(numColumns, 1);
} catch (ClassCastException e) {
return new SpanSize(1, 1);
}
default:
LineItem lineitem = mItems.get(position);
if (lineitem != null && lineitem.mediaItem != null && lineitem.mediaItem.getRating() != null && lineitem.mediaItem.getRating() == 5) {
return new SpanSize(2, 2);
}
return new SpanSize(1, 1);
}
} catch (IndexOutOfBoundsException e) {
MyApplication.toastSomething(mActivity, e); // Seen on firebase
return new SpanSize(1, 1);
}
}));
return layoutManager;
} else {
return new LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false);
}
}
There are header items with a full column span: return new SpanSize(numColumns, 1);
Other items are with span width 2 or 2. The number of columns is 5.
After collecting the items, they are used for the RV adapter. The problem is that the order in the rendered RV is not the same as the items. Result: Pic
Could you please fix that? I can confirm 100% that the default GridLayoutManager is working with these items.
The text was updated successfully, but these errors were encountered:
I'm afraid that's not possible at the moment. The LayoutManager will order items so they don't leave any gaps. That means that if an item with can fit in a previous position, it will be placed there.
That said, the LayoutManager could be modified to support sections and only do this kind of ordering inside those sections. However, tomorrow I'm leaving for a business trip and I won't be back for at least a week, so I don't think I'll have time to look at this until then.
Ok. Thanks for your message. Maybe you could check if the span is equal to the number of columns, in this case, you don't fill the gaps. This would be an easy workaround. I understand the problem.
I have the following code to collect my items to show in my RV:
There are header items with a full column span:
return new SpanSize(numColumns, 1);
Other items are with span width 2 or 2. The number of columns is 5.
After collecting the items, they are used for the RV adapter. The problem is that the order in the rendered RV is not the same as the items. Result:
Pic
Could you please fix that? I can confirm 100% that the default GridLayoutManager is working with these items.
The text was updated successfully, but these errors were encountered: