OnScrolledStateChanged一次又一次被调用,所以我无法获得所选页面:
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
View centerView = pagerSnapHelper.findSnapView(mLayoutManager);
int pos = mLayoutManager.getPosition(centerView);
if (newState == RecyclerView.SCROLL_STATE_IDLE || (pos == 0 && newState == RecyclerView.SCROLL_STATE_DRAGGING)) {
Log.d("Snapped Item Position:",""+pos);
// adapter.removeItem(pos);
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}
});`