android 的ListView中,如何判断其内容已滚动到最顶部或者最底部

2024-12-04 03:36:44
推荐回答(2个)
回答1:

给listview设置滑动监听器,来判断内容滑动到底部或者顶部listview.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if(firstVisibleItem==0){
Log.e("log", "滑到顶部");
}
if(visibleItemCount+firstVisibleItem==totalItemCount){
Log.e("log", "滑到底部");
}
}
});

回答2:

根据这个方法检测:
[java]
getListView().setOnScrollListener(new OnScrollListener() {
@Override www.2cto.com
public void onScrollStateChanged(AbsListView view, int scrollState) {
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if(firstVisibleItem==0){
Log.e("log", "滑到顶部");
} www.2cto.com
if(visibleItemCount+firstVisibleItem==totalItemCount){
Log.e("log", "滑到底部");
}
}
});