Centering the Last Row of a RecyclerView GridLayoutManager

Nathan Sokalski 4,111 Reputation points
2022-03-08T04:39:56.49+00:00

I have a RecyclerView that uses a GridLayoutManager, and I want to center the last row. Most of the stuff I have found suggests using a SpanSizeLookup & overriding GetSpanSize. I have done this, and (I think) been able to set the span size, but that forces the following items to be pushed farther as well. For example, if my GridLayoutManager has a span size of 5, my last row has 4 items, and my override returns 2 for those last 4 items, they will end up being split into 2 rows of 2. What I need to do is be able to specify the column index along with the span so that the items overlap (even though it will not visually appear that way, since the overlapping area is just empty space). Is there a way to do this?

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-03-09T05:51:38.47+00:00

    Hello,​

    What I need to do is be able to specify the column index along with the span so that the items overlap

    Do you want to change the column index based on the span? If so, I think this answer is no, RecyclewView is different from the GridLayout, you cannot change the column index.

    If you want to center the items, You can try to use FlexboxLayoutManager

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.