我有这个代码
public class CustomLinearLayoutManager extends LinearLayoutManager
{
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
{
super.onLayoutChildren(recycler, state);
int childCount = getChildCount();
View lastChild = getChildAt(childCount - 1);
// Do some stuff
}
}
出于某种原因有时lastChild
是null
。怎么会这样?
正如评论中提到的,lastChild
是 null 因为根本没有孩子,所以新的问题是为什么打电话后没有孩子super.onLayoutChildren(recycler, state);
?