获取屏幕内可见的View
recyclerView.getChildAt(position)
recyclerView.layoutManager?.findViewByPosition(pos)
recyclerView.findViewHolderForLayoutPosition(position)?.itemView
获取超出屏幕的不可见View
1、在你的mAdapter 中定义一个map
2、在你的mAdapter 中重写onViewDetachedFromWindow
class ComplaintDataSubmitAdapter() :BaseAdapter<MultiItemEntity, BaseViewHolder>(null) {
val viewHolderMap=ArrayMap<Int,View>()
override fun onViewDetachedFromWindow(holder: BaseViewHolder) {
super.onViewDetachedFromWindow(holder)
viewHolderMap[holder.adapterPosition] = holder.itemView
}
Use 得到屏幕外的View--> child
for (index in 0 until mAdapter.data.size) {
val item = mAdapter.data[index]
var child= recycleView.layoutManager?.findViewByPosition(index)
if (child==null&&mAdapter.viewHolderMap.isNotEmpty()&&mAdapter.viewHolderMap.size>index){
child=mAdapter.viewHolderMap[index]
}
在Activity退出清空map
override fun onDestroy() {
if (mAdapter.viewHolderMap.isNotEmpty()){
mAdapter.viewHolderMap.clear()
}
super.onDestroy()
}
网友评论