RecyclerView not recycling views if the view count is small

前端 未结 1 1373
离开以前
离开以前 2021-02-15 18:40

I\'ve been dealing with a strange behavior in Recycler View, if the view count in the adapter is small, in my case with size 5, the views are not being recycled and onBindViewHo

相关标签:
1条回答
  • 2021-02-15 18:45

    It is normal behavior, but you can tweak it with:

    recyclerView.setItemViewCacheSize(int);
    

    About the second part of the question - you're right! Store the "activated" position as a variable in your adapter. In onBindViewHolder() do something like:

    holder.itemView.setActivated(holder.getAdapterPosition() == lastSelectedPos);
    
    0 讨论(0)
提交回复
热议问题