为什么firstVisibleItem有时在Android的onScrollListener onScroll上?

时间:2017-10-11 07:57:51

标签: android listview onscrolllistener

ListView有标题视图并注册AbsListView.OnScrollListener以加载更多项目。

为ListView添加了标题视图:

headerView = new LinearLayout(getActivity());
headerView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));
listView.addHeaderView(headerView);

OnScrollListener的回调:

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    ...
}

检查onScroll上的参数时,firstVisibleItem值很奇怪,并且在向下滚动后突然以 -1 返回。

logcat的:

firstVisibleItem= 0 , visibleItemCount= 5 , totalItemCount= 22
firstVisibleItem= 0 , visibleItemCount= 5 , totalItemCount= 22
firstVisibleItem= 0 , visibleItemCount= 5 , totalItemCount= 22
firstVisibleItem= -1 , visibleItemCount= 6 , totalItemCount= 22
firstVisibleItem= -1 , visibleItemCount= 6 , totalItemCount= 22

有谁知道原因?

0 个答案:

没有答案