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