Using layout_columnWeight & layout_rowWeight in RecyclerView

Nathan Sokalski 4,111 Reputation points
2025-03-28T00:48:15.5633333+00:00

I have a Fragment with a root element of a 2×3 GridLayout, which contains several RecyclerView(s).

The RecyclerView(s) at [1,0], [0,1] & [1,2] have either a dynamic (but not changing) width or height, and I want the RecyclerView at [1,1] to fill the remaining space.

I attempted to do this using a combination of layout_width="0dp", layout_width="wrap_content", layout_height="0dp", layout_height="wrap_content", layout_columnWeight="1" & layout_rowWeight="1".

However, when I call SetLayoutManager & SetAdapter in OnResume it does not call OnCreateViewHolder or OnBindViewHolder, I am guessing because they have widths/heights of 0 at that point.

I have confirmed that the Adapters do have data and that ItemCount do return the correct values. I have tried calling the Notify methods, with no success.

My issue is:

What can I do to force the GridLayout & RecyclerView(s) to update the layout in OnResume (or wherever is appropriate) when initially creating my Fragment (without manually calculating the elements)?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,074 questions
{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.