Patrick Patrick - 2 months ago 26
Android Question

RecyclerView recalculate WRAP_CONTENT

With version 23.2 we can now use

WRAP_CONTENT
for
recyclerView
height, which is great. I am doing this, however I want to recalculate the height after an item is added (or removed) to the adapter (thus increasing or decreasing the height).

My particular
RecyclerView
is starting with 1 item, and then adding items as the user makes selection. So I need the
RecyclerView
layout to increase in height, up to a point. Ideally this would happen with a smooth animation when the list increases or decreases.

How can we make it
WRAP_CONTENT
after it has been laid out?

Tried:

recyclerview.requestLayout();

recyclerview.invalidate();

Answer

I would expect it to work with View.invalidate().

If that does not work, try to call either requestLayout or invalidate on the parent view.

Comments