@Override public void run() { rvFeed.smoothScrollToPosition(0); feedAdapter.showLoadingView(); } }, 500);
@Override public void onTabSelected(TabLayout.Tab tab) { pager.smoothScrollToPosition(tab.getPosition()); }
@Override public void onTabSelected(TabLayout.Tab tab) { pager.smoothScrollToPosition(tab.getPosition()); }
@Override public void run() { mCardGalleryWidth = mRecyclerView.getWidth(); mCardWidth = mCardGalleryWidth - ScreenUtil.dip2px(mContext, 2 * (mPagePadding + mShowLeftCardWidth)); mOnePageWidth = mCardWidth; mRecyclerView.smoothScrollToPosition(mCurrentItemPos); onScrolledChangedCallback(); } });
@Override public void onRefresh() { recyclerView.smoothScrollToPosition(0); presenter.doRefresh(); }
@Override public void onRefresh() { recyclerView.smoothScrollToPosition(0); presenter.doRefresh(); }
public void handleSuggestions(@NonNull final List<SuggestionItem> suggestions) { if (DEBUG) Log.d(TAG, "handleSuggestions() called with: suggestions = [" + suggestions + "]"); suggestionsRecyclerView.smoothScrollToPosition(0); suggestionsRecyclerView.post(() -> suggestionListAdapter.setItems(suggestions)); if (errorPanelRoot.getVisibility() == View.VISIBLE) { hideLoading(); } }
@Override public void onRefresh() { int firstVisibleItemPosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition(); if (firstVisibleItemPosition == 0) { presenter.doRefresh(); return; } recyclerView.scrollToPosition(5); recyclerView.smoothScrollToPosition(0); }
public void addItem(Program program) { if (results.size() > 0) { int position = results.size() - 1; results.add(position, program); if (adapter != null) { if (results.size() <= 4) { adapter.notifyItemInserted(position); adapter.notifyItemRangeChanged(position, results.size() - position); } else { adapter.notifyDataSetChanged(); recycler.smoothScrollToPosition(results.size() - 1); } } } }
private void scrollToSelected() { if (player == null) return; final int currentPlayingIndex = player.getPlayQueue().getIndex(); final int currentVisibleIndex; if (itemsList.getLayoutManager() instanceof LinearLayoutManager) { final LinearLayoutManager layout = ((LinearLayoutManager) itemsList.getLayoutManager()); currentVisibleIndex = layout.findFirstVisibleItemPosition(); } else { currentVisibleIndex = 0; } final int distance = Math.abs(currentPlayingIndex - currentVisibleIndex); if (distance < SMOOTH_SCROLL_MAXIMUM_DISTANCE) { itemsList.smoothScrollToPosition(currentPlayingIndex); } else { itemsList.scrollToPosition(currentPlayingIndex); } }
@Override public boolean scrollToNext() { int pos = mScrollMode == SCROLL_ITEM ? getLinearLayoutManager().findFirstVisibleItemPosition() : getLinearLayoutManager().findLastCompletelyVisibleItemPosition(), next = pos != RecyclerView.NO_POSITION ? pos + 1 : RecyclerView.NO_POSITION; if (next != RecyclerView.NO_POSITION && next < mRecyclerView.getAdapter().getItemCount()) { mRecyclerView.smoothScrollToPosition(next); return true; } else { return false; } }
private void appendLog(String msg) { adapter.addString(msg); logsRecyclerView.smoothScrollToPosition(adapter.getItemCount() - 1); }
private void appendBitmap(Bitmap bitmap) { adapter.addBitmap(bitmap); logsRecyclerView.smoothScrollToPosition(adapter.getItemCount() - 1); }
/** * Send the Recycler a request to scroll the content to a specific item in the binder. * * @param animated if animated is set to true the scroll will happen with an animation. */ public void requestScrollToPosition(final int position, final boolean animated) { SectionsRecyclerView sectionsRecyclerView = mSectionsRecyclerView; if (sectionsRecyclerView == null) { return; } if (animated) { sectionsRecyclerView.getRecyclerView().smoothScrollToPosition(position); return; } sectionsRecyclerView.getRecyclerView().scrollToPosition(position); }
@Test public void testScrollToNextItem() { when(adapter.getItemCount()).thenReturn(10); when(layoutManager.findFirstVisibleItemPosition()).thenReturn(0); helper = new KeyDelegate.RecyclerViewHelper(recyclerView, KeyDelegate.RecyclerViewHelper.SCROLL_ITEM); assertTrue(helper.scrollToNext()); verify(recyclerView).smoothScrollToPosition(eq(1)); when(layoutManager.findFirstVisibleItemPosition()).thenReturn(RecyclerView.NO_POSITION); assertFalse(helper.scrollToNext()); }
@Test public void testScrollToPreviousItem() { when(adapter.getItemCount()).thenReturn(10); when(layoutManager.findFirstVisibleItemPosition()).thenReturn(5); helper = new KeyDelegate.RecyclerViewHelper(recyclerView, KeyDelegate.RecyclerViewHelper.SCROLL_ITEM); assertTrue(helper.scrollToPrevious()); verify(recyclerView).smoothScrollToPosition(eq(4)); when(layoutManager.findFirstVisibleItemPosition()).thenReturn(0); assertFalse(helper.scrollToPrevious()); when(layoutManager.findFirstVisibleItemPosition()).thenReturn(RecyclerView.NO_POSITION); assertFalse(helper.scrollToPrevious()); }
@Test public void testScrollToNextPage() { when(adapter.getItemCount()).thenReturn(10); when(layoutManager.findLastCompletelyVisibleItemPosition()).thenReturn(8); helper = new KeyDelegate.RecyclerViewHelper(recyclerView, KeyDelegate.RecyclerViewHelper.SCROLL_PAGE); assertTrue(helper.scrollToNext()); verify(recyclerView).smoothScrollToPosition(eq(9)); when(layoutManager.findLastCompletelyVisibleItemPosition()).thenReturn(9); assertFalse(helper.scrollToNext()); }
@Implementation public void smoothScrollToPosition(int position) { directly().smoothScrollToPosition(position); scrollPosition = position; }
@Config(shadows = ShadowRecyclerView.class) @Test public void testScrollToTop() { RecyclerView recyclerView = activity.findViewById(R.id.recycler_view); recyclerView.smoothScrollToPosition(1); assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(1); activity.findViewById(R.id.toolbar).performClick(); assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(0); }
@Config(shadows = ShadowRecyclerView.class) @Test public void testScrollToTop() { verify(userManager).getUser(eq("username"), userCaptor.capture()); userCaptor.getValue().onResponse(user); RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view); recyclerView.smoothScrollToPosition(1); assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(1); TabLayout.Tab tab = ((TabLayout) activity.findViewById(R.id.tab_layout)).getTabAt(0); tab.select(); tab.select(); assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(0); }