使用ListView的时候,会有判断指定项是否正在显示的需求,其实很简单,代码如下:
1 private boolean isShowing(int position) { 2 int showViewCount =mainList.getChildCount(); 3 int lastPosition = mainList.getLastVisiblePosition(); 4 return position <= lastPosition 5 && position > lastPosition - showViewCount; 6 }