Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make RecyclerView update its layout?

I have a RecyclerView with a bunch of custom views which may change height after a while, because they contain ImageViews 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.

like image 447
Nilzor Avatar asked Aug 14 '14 11:08

Nilzor


People also ask

How do I update my RecyclerView adapter data?

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.

What is LayoutManager in RecyclerView?

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.

Is RecyclerView a layout?

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.


1 Answers

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.

like image 100
Barad Avatar answered Sep 20 '22 15:09

Barad