Search code examples
androidandroid-recyclerviewgridlayoutmanager

Android RecyclerView StaggeredGridLayoutManager vertical order


how can I set StaggeredGridLayoutManager to first use one column and then the other one instead of doing left-right-left-right order? I want it to use the first row for the first half of the list items and then use the second row for the second half.


Solution

  • I don't think there is an option for that specifically.

    You should just handle it yourself: If you want to use the first half of the list for the left side (even numbers) and the other half of the list for the right side (odd numbers) you can do so by handling the callback differently.

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Object myObject;
        if(position % 2 == 0) {
            myObject = myList.get(position / 2);
        } else {
            myObject = myList.get(myList.size() / 2 + position / 2);
        }
        holder.bind(myObject); // display stuff.
    }
    

    You would obviously need to add some more checks, but this would allow you to populate the 2 columns with the data from the front and middle of the list.