Pre-Measuring a RecyclerView

Nathan Sokalski 4,106 Reputation points
2024-10-13T02:22:46.6466667+00:00

I have a Custom View that inherits from RecyclerView. Once created, the RecyclerView will always have the same number of items, all of which will remain the same size once created. All other items on the page will remain the same size as well (except of course if the user rotates their phone). I want the RecyclerView to use whatever space the user specifies when using the View in their layout (whether it be a fixed size, match_parent, or something like layout_weight). All the items will be the same size (which I will calculate during initialization to make each item using rvwidth/itemcount) so that the total is the available width. However, because layout involves multiple passes, the width is not available during the initial layout in methods such as OnCreateViewHolder & OnBindViewHolder. What should I do to be able to get the available space when creating & binding my RecyclerView?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,354 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,864 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.