Reputation: 219
I read that RecyclerView should never have layout_height="wrap_content" because it won't recycle the views.
I tested this by creating that with 100 items.
I scrolled to the bottom and used layoutInspector. It showed only a couple items under the RecyclerView, not 100. I also tested with a recycerview layout_height=200dp and saw the same result.
It seems the views are still being recycled. Am I misinterpreting what he's saying or are layout_height=wrap_content and layout_height=fixedDp irrelevant to recycling?
Upvotes: 0
Views: 124
Reputation: 1007399
android:layout_height
values of wrap_content
or a fixed height are irrelevant to recycling.
However, android:layout_height="wrap_content"
is not a good idea in general for vertically-scrolling widgets, such as a RecyclerView
with a vertical LinearLayoutManager
. Since the content varies, the size may be unpredictable. Use something else to control the height to be what you want regardless of the content, such as constraining its top and bottom within a ConstraintLayout
.
Upvotes: 1