I am implementing below list using RecyvlerView
. I have done it using StaggeredGridLayoutManager
NOTE: This screenshot is with GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS
Every thing works fine, but the issue is with order of item arrangement, it's arranging items like:
| 0 | 1 |
| 3 | 2 |
| 4 | 5 |
| 7 | 6 |
If you check above image you will notice 2nd item is drawing in Right side while 4th item is coming at left side but my requirement is to start every row from right side i.e 4th item will come in right side of grid. I have try both GapStrategy StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS
and StaggeredGridLayoutManager.GAP_HANDLING_NONE
. If I use GAP_HANDLING_NONE
then items are not visible yet functions of adapter are called but the output is
blank screen.
Is there any function to force StaggeredGridLayoutManager to start drawing from right side for new row?
I am calculating item height using below code:
public static void isSquired(View view, int position) {
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) view.getContext()).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
boolean isSquare = isSquare(position);
ViewGroup.LayoutParams lp = view.getLayoutParams();
if (isSquare) {
lp.width = width / 2;
lp.height = width / 2;
}else{
lp.width = width / 2;
lp.height = (width / 2)+70;
}
view.setLayoutParams(lp);
view.requestLayout();
}
public static boolean isSquare(int position) {
int mod = position % 4;
return mod == 1 || mod == 3;
}
RecyclerView initialisation:
StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
//manager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
manager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
recyclerView.setLayoutManager(manager);
recyclerView.setNestedScrollingEnabled(false);