Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use RecyclerView setHasFixedSize(true)?

I've read the Android developer info and a number of SO posts and RecyclerView articles. I'm still unclear as to whether I can use the:

recyclerView.setHasFixedSize(true);

method on my RecyclerView list. The size of my RecyclerView list will constantly change as CardView items are dynamically added and deleted over time. However, the size (height and length) of each CardViews is fixed. Please advise.

like image 261
AJW Avatar asked Oct 19 '22 16:10

AJW


1 Answers

Yes, you can use

recyclerView.setHasFixedSize(true); 

as long as height and width of recyclerview remains the same.

From Android Developer:

public void setHasFixedSize (boolean hasFixedSize)

RecyclerView can perform several optimizations if it can know in advance that changes in adapter content cannot change the size of the RecyclerView itself. If your use of RecyclerView falls into this category, set this to true. Parameters hasFixedSize true if adapter changes cannot affect the size of the RecyclerView.

like image 193
JAAD Avatar answered Oct 21 '22 05:10

JAAD