how to know the previous and new positions?

为君一笑 提交于 2019-12-06 03:54:24
int count = 0; //field variable
int initial_position;  

@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    if(count == 0) {
       initial_position = mLayoutManager.findFirstVisibleItemPosition();
   }

    count ++;

    // get newstate position
    if(newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
        View centerView = snapHelper.findSnapView(mLayoutManager);
        if(centerView != null){
            int pos = mLayoutManager.getPosition(centerView);

            count = 0; // in idle state clear the count again 
            Log.e("Snapped Item Position:",""+pos);
        }
    }
}

initial_position = starting position

pos = ending position

Happy coding :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!