判断最后一项,亲测可用,当然网上还有很多其他的方法,不同场景的方式可能不一样
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if(view.getId() == R.id.wait_For_Choice){
float currentHeight = view.getHeight();
float currentHeight1 = view.getScrollY();
UtilsLog.e("currentHeight " + currentHeight);
UtilsLog.e("currentHeight1 " + currentHeight1);
if ((totalItemCount > 0) && (view.getLastVisiblePosition() == totalItemCount - 1)) {
UtilsLog.d("view.getBottom() " + view.getBottom());
UtilsLog.d("view.getChildCount() " + view.getChildCount());
UtilsLog.d("view.getChildAt(view.getChildCount()-1).getBottom() " + view.getChildAt(view.getChildCount() - 1).getBottom());
if (currentHeight == view.getChildAt(view.getChildCount()-1).getBottom()) {
UtilsLog.e("end");
}
}
}
}
查看坐标getLeft, getRight, getTop, getBottom解惑
下面代码是摘自网上的 没测试过,先留着 http://www.lai18.com/content/1506534.html
如果ListView加了padding属性的话,判断是否完全显示的时候就不能根据>=0判断,而是应该加上paddingTop的高度
if (mListView.getChildCount() > 0 && mListView.getFirstVisiblePosition() == 0 && mListView.getChildAt(0).getTop() >= mListView.getPaddingTop()) {
return true;
}
先解释几个接口的作用:
ListView.getChildCount()
返回的是这个listView当前显示出来的item数量,也就是在屏幕上可以看到的数量。
ListView.getChildAt(int pos)
返回的是这个listView当前显示出来的item中的第pos项,也就是说索引是从显示出来的第一项开始计算的,如果屏幕上方有n个item看不见,那么这个函数的返回值就是n
ListView.getFirstVisiblePosition()
返回值是当前可以看到的第一个item,在所有item中(包括看不到的)的位置。
View.getTop()
返回值是这个View相对于它的父控件的top值,对于item而言,如果item只有一半显示出来(下半部分),那么返回值应该是
- 这个item的高度