1
我有这样的代码 的Android LinearLayoutManager#getChildAt(INT)retuns空
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
为空,因为根本没有孩子,所以新的问题是为什么在调用super.onLayoutChildren(recycler, state);
后没有孩子?
没有孩子,'getChildCount()'返回0,'getChildAt(-1)'返回'null'。 – earthw0rmjim
@ user13好点,我会更新答案。 –