You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
当Recyclerview设置为StaggeredGridLayoutManager和GridLayoutManager时,item的复用机制就失效了,新增的数据都会调用onCreateViewHolder方法重新渲染布局,设置LinearLayoutmanager就不会再新增数据时一直调用onCreateViewHolder。
brvah版本:4.1.4
产生的问题:数据过多时列表开始卡顿
下面是两个adapter的比较代码,其他代码是一致的,就改了adapter的代码
/** 原生adapter **/
class ListAdapter : RecyclerView.Adapter<ListAdapter.MyViewHolder>() {
val dataList = mutableListOf()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
LogUtil.e("onCreateViewHolder")
val binding = ItemVideoBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return MyViewHolder(binding)
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val item = dataList[position]
holder.binding.ivIcon.loadImage(item.img) //这里不要传圆角,传了加载gif时不会播放gif
holder.binding.tvTitle.text = item.title
holder.binding.tvAuthorName.text = item.author_name
holder.binding.ivAuthor.loadImage(item.author_header)
holder.binding.root.viewClick {
clickListener?.invoke(this, holder.binding.root, position)
}
}
override fun getItemCount(): Int {
return dataList.size
}
fun submitList(list: List<VideoInfo>) {
dataList.clear()
dataList.addAll(list)
notifyDataSetChanged()
}
fun addAll(list: List<VideoInfo>) {
dataList.addAll(list)
notifyItemRangeInserted(dataList.size - list.size, list.size)
}
private var clickListener:((adapter: RecyclerView.Adapter<ListAdapter.MyViewHolder>, view: View, position: Int) -> Unit)?=null
fun setOnDebouncedItemClick(block: (adapter: RecyclerView.Adapter<ListAdapter.MyViewHolder>, view: View, position: Int) -> Unit) {
clickListener = block
}
class MyViewHolder(val binding: ItemVideoBinding) : RecyclerView.ViewHolder(binding.root){
}
}
Describe the bug
当Recyclerview设置为StaggeredGridLayoutManager和GridLayoutManager时,item的复用机制就失效了,新增的数据都会调用onCreateViewHolder方法重新渲染布局,设置LinearLayoutmanager就不会再新增数据时一直调用onCreateViewHolder。
brvah版本:4.1.4
产生的问题:数据过多时列表开始卡顿
下面是两个adapter的比较代码,其他代码是一致的,就改了adapter的代码
/** 原生adapter **/
class ListAdapter : RecyclerView.Adapter<ListAdapter.MyViewHolder>() {
val dataList = mutableListOf()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
LogUtil.e("onCreateViewHolder")
val binding = ItemVideoBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return MyViewHolder(binding)
}
/** brvah **/
// private class ListAdapter : BaseQuickAdapter<VideoInfo, ListAdapter.VH>() {
// class VH(
// parent: ViewGroup,
// val binding: ItemVideoBinding = ItemVideoBinding.inflate(
// LayoutInflater.from(parent.context), parent, false
// ),
// ) : RecyclerView.ViewHolder(binding.root)
//
// override fun getItemViewType(position: Int, list: List): Int {
// return position
// }
//
// override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
// LogUtil.e("onCreateViewHolder")
// return VH(parent)
// }
//
//
// override fun onBindViewHolder(holder: VH, position: Int, item: VideoInfo?) {
// item ?: return
// holder.binding.run {
//// ivIcon.loadVideoFrameImage(item.img, 10f)
// ivIcon.loadImage(item.img) //这里不要传圆角,传了加载gif时不会播放gif
// tvTitle.text = item.title
// tvAuthorName.text = item.author_name
// ivAuthor.loadImage(item.author_header)
// }
// }
// }
The text was updated successfully, but these errors were encountered: