njsokalski avatar image
0 Votes"
njsokalski asked YonglunLiu-MSFT commented

RecyclerView with GridLayoutManager: Scrolling Both Directions

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?

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you don't want to use HorizontalScrollView or ScrollView, you need to search and refer to FixedGridLayoutManager written by devunwired, and to implement it by C#.

Then you could use it as the RecyclerView's layout manager:

 FixedGridLayoutManager layoutManager = new FixedGridLayoutManager();
 layoutManager.setTotalColumnCount(adapter.getItemCount()); // This probably needs to update when item count is changed
0 Votes 0 ·

I have not heard from you for a couple of days. Please let me know if there is anything that I can help here.

0 Votes 0 ·

0 Answers