我有下面的代码,我的适配器和我的LayoutManager(网格)设置在此代码之上,但
返回的值findLastCompletelyVisibleItemPosition
有时是错误的(例如,返回1而不是5) 我认为这种方法很少有问题,
我怎样才能获得好的价值?
holder.mRecyclerViewImage.postDelayed(new Runnable() {
@Override
public void run() {
if (holder.mLastVisibleItems == -1)
holder.mLastVisibleItems = holder.mGridLayoutManager.findLastCompletelyVisibleItemPosition();
Log.d("myItemPosition", holder.mLastVisibleItems + "");
if (holder.mLastVisibleItems == 0 || holder.mLastVisibleItems == -1)
return;
int deleted = 0;
ArrayList<String> saveList = new ArrayList<>(listUrlImg);
while (holder.mLastVisibleItems + 1 < listUrlImg.size()) {
listUrlImg.remove(holder.mLastVisibleItems + 1);
deleted++;
}
holder.mRecyclerViewImage.setAdapter(new ImageAdapter(saveList, listUrlImg, deleted));
}
}, 100);