简体   繁体   English

如何知道listview滚动是否到达底部/顶部

[英]how to know if listview scroll has reached the bottom/Top

I have an android program and I want to know when the user scrolled to the bottom/ top of a listview. 我有一个android程序,我想知道用户何时滚动到列表视图的底部/顶部。 The thing is: I scroll the list by using buttons and the smoothScrollBy method. 事情是:我使用按钮和smoothScrollBy方法滚动列表。

Tried using this for bottom, but doesn't work, I still get the last element still "half-cut" 尝试使用它作为底部,但不起作用,我仍然得到的最后一个元素仍然是“半切”

if (yourListView.getLastVisiblePosition() == yourListView.getAdapter().getCount() -1 &&
yourListView.getChildAt(yourListView.getChildCount() - 1).getBottom() <= yourListView.getHeight()) {

    //It is scrolled all the way down here

}

You need to implement OnScrollListener in your Activity then override onScroll method and add the following code : 您需要在Activity中实现OnScrollListener ,然后重写onScroll方法并添加以下代码:

@Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    if (visibleItemCount + firstVisibleItem >= totalItemCount){
        System.out.println("you reached the bottom");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM