3 回答
TA贡献1836条经验 获得超4个赞
较晚的答案,但是如果您只想检查ListView是否一直向下滚动,而不创建事件侦听器,则可以使用以下if语句:
if (yourListView.getLastVisiblePosition() == yourListView.getAdapter().getCount() -1 &&
yourListView.getChildAt(yourListView.getChildCount() - 1).getBottom() <= yourListView.getHeight())
{
//It is scrolled all the way down here
}
首先,它检查是否在最后一个可能的位置。然后,它检查最后一个按钮的底部是否与ListView的底部对齐。您可以执行类似的操作来知道它是否始终位于顶部:
if (yourListView.getFirstVisiblePosition() == 0 &&
yourListView.getChildAt(0).getTop() >= 0)
{
//It is scrolled all the way up here
}
TA贡献1993条经验 获得超5个赞
我这样做的方式:
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE
&& (listView.getLastVisiblePosition() - listView.getHeaderViewsCount() -
listView.getFooterViewsCount()) >= (adapter.getCount() - 1)) {
// Now your listview has hit the bottom
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
- 3 回答
- 0 关注
- 477 浏览
添加回答
举报