I have a RecyclerView
as the following image presents:
This is the setup code for this RecyclerView
:
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 2);
dataRecyclerView.setLayoutManager(layoutManager);
dataRecyclerView.addItemDecoration(new GridSpacingItemDecoration(...);
dataRecyclerView.setItemAnimator(new DefaultItemAnimator());
after starting a new activity where I update the selected item of the RecyclerView, the RecyclerView is re-populated with new data to reflect the new change, but I get the following result:
And when I scroll down, I get this gap:
I tried calling RecyclerView#invalidate()
, #invalidateItemDecorations()
, #requestLayout()
after the refresh but to no avail; & I'm also not calling setHasFixedSize(true)
on the RecyclerView
.
What is the problem exactly ? How can I resize the child items so as they wrap their content precisely after refreshing?
(P.S: I tried refreshing without making any changes & nothing happened, which proves my theory that the issue arises only when a child item's height changes.)