RecyclerView作为我们常用的数据列表展示组件,它可以包含若干的子视图(child),那就会涉及到添加、删除、隐藏、查找等等操作,所以Android SDK提供了一个专门负责管理RecyclerView子视图的类,就是ChildHelper类。今天我们就来看看ChildHelper的源码实现。它的官方说明如下:
Helper class to manage children.
It wraps a RecyclerView and adds ability to hide some children. There are two sets of methods provided by this class. Regular methods are the ones that replicate ViewGroup methods like getChildAt, getChildCount etc. These methods ignore hidden children.
When RecyclerView needs direct access to the view group children, it can call unfiltered methods like get getUnfilteredChildCount or getUnfilteredChildAt.
大概的意思就是说,ChildHelper是用来管理子视图的,它包含一对子视图的操作功能。它提供了两种方式,通常会使用ViewGroup的方法,比如getChildAt等,这些方法会忽略掉不可见的childview,如果RecyclerView想直接访问children