找出ListView是否滚动到底部?

我可以确定ListView是否滚动到底部吗?我的意思是说最后一项是完全可见的。



蓝山帝景
浏览 479回答 3
3回答

HUH函数

较晚的答案,但是如果您只想检查ListView是否一直向下滚动,而不创建事件侦听器,则可以使用以下if语句:if (yourListView.getLastVisiblePosition() == yourListView.getAdapter().getCount() -1 &&&nbsp; &nbsp; yourListView.getChildAt(yourListView.getChildCount() - 1).getBottom() <= yourListView.getHeight()){&nbsp; &nbsp; //It is scrolled all the way down here}首先,它检查是否在最后一个可能的位置。然后,它检查最后一个按钮的底部是否与ListView的底部对齐。您可以执行类似的操作来知道它是否始终位于顶部:if (yourListView.getFirstVisiblePosition() == 0 &&&nbsp; &nbsp; yourListView.getChildAt(0).getTop() >= 0){&nbsp; &nbsp; //It is scrolled all the way up here}

ibeautiful

我这样做的方式:listView.setOnScrollListener(new AbsListView.OnScrollListener() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void onScrollStateChanged(AbsListView view, int scrollState) {&nbsp; &nbsp; &nbsp; &nbsp; if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && (listView.getLastVisiblePosition() - listView.getHeaderViewsCount() -&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listView.getFooterViewsCount()) >= (adapter.getCount() - 1)) {&nbsp; &nbsp; &nbsp; &nbsp; // Now your listview has hit the bottom&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {&nbsp; &nbsp; }});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android