RecyclerView with GridLayoutManager: Scrolling Both Directions

Nathan Sokalski 4,111 Reputation points
2022-05-14T16:48:28.94+00:00

I have a RecyclerView that uses a GridLayoutManager. The number of rows/columns will vary in different scenarios, all the elements that will be displayed are the same size, and I need to be able to scroll both vertically and horizontally. I have tried the following:

this.rvPuzzle.SetLayoutManager(new SquareLayoutManager(this, this.Puzzle.ColumnCount, GridLayoutManager.Vertical, false));
this.rvPuzzle.SetAdapter(new SquareAdapter(this.Puzzle.FlatSquares));

This makes the elements the correct height & vertically scrollable, but causes the elements to be horizontally cropped to fit them all on the screen (and therefore obviously not horizontally scrollable, since all columns are now visible). I tried creating a custom Layout Manager by inheriting from GridLayoutManager and overriding CanScrollHorizontally() & CanScrollVertically() as follows:

public override bool CanScrollHorizontally() { return true; }
public override bool CanScrollVertically() { return true; }

However, this did not make any difference. Is there any way to enable scrolling in both directions without an extra HorizontalScrollView and/or ScrollView?

Developer technologies .NET Xamarin
{count} votes

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.