@Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { // we want the grid to scroll over the top of the toolbar but for the toolbar items // to be clickable when visible. To achieve this we play games with elevation. The // toolbar is laid out in front of the grid but when we scroll, we lower it's elevation // to allow the content to pass in front (and reset when scrolled to top of the grid) if (newState == RecyclerView.SCROLL_STATE_IDLE && layoutManager.findFirstVisibleItemPosition() == 0 && layoutManager.findViewByPosition(0).getTop() == grid.getPaddingTop() && toolbar.getTranslationZ() != 0) { // at top, reset elevation toolbar.setTranslationZ(0f); } else if (newState == RecyclerView.SCROLL_STATE_DRAGGING && toolbar.getTranslationZ() != -1f) { // grid scrolled, lower toolbar to allow content to pass in front toolbar.setTranslationZ(-1f); } } };
firstVisiblePosition = ((LinearLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition(); } else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) { firstVisiblePosition = ((GridLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
position = ((LinearLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition(); } else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) { position = ((GridLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition(); position = ((LinearLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition(); } else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) { position = ((GridLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();