Measure Recyclerview before it appears

Are you trying to measure the view before adding it? If so, that is dangerous.

Also, in terms of RecyclerView, unfortunately, existing layout managers don't yet support WRAP_CONTENT. They rely on the base implementation which supports match_paren & exact dimensions.

If you know your item's height, you can extend GridLayoutManager, override onMeasure and measure it there yourself.


Thanks to yigit post, I could finally calculate future recyclerView height by manually inflating a child's view, measuring it with :

final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, View.MeasureSpec.AT_MOST);

And finally multiplying its measuredHeight by the number of lines contained in the gridLayoutManager. Hope WRAP_CONTENT support will come soon for RecycleViews layoutManagers.