I have a RecyclerView
with a bunch of custom views which may change height after a while, because they contain ImageView
s which load their image asynchronously. The RecyclerView
does not pick up on this layout change, although I call forceLayout
on the ImageView
, and the RecyclerView
is initialized with setHasFixedSize(false)
. All container-parents of the ImageView
have set android:layout_height="wrap_content"
.
How can I make the RecyclerView
update its layout? With good'ol ListView
this was not a problem.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Open build. gradle and add Recycler view & Card view library dependencies. Step 3 − Add the following code to res/layout/activity_main.
A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user.
The items in your RecyclerView are arranged by a LayoutManager class. The RecyclerView library provides three layout managers, which handle the most common layout situations: LinearLayoutManager arranges the items in a one-dimensional list.
You can use the notifyDataSetChanged
in the Adapter
for the RecyclerView
if all your images change at the same time or notifyItemChanged(int position)
if only one of the items has changed. This will tell the RecyclerView
to rebind the particular View
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With