@Test public void testSwipeDownKeepsItemSnappedToTopOfList() { setUpPagedListView(ITEMS_PER_PAGE * 2 ); onView(withId(R.id.recycler_view)).perform(scrollToPosition(ITEMS_PER_PAGE)); onView(withId(R.id.recycler_view)) .perform(actionOnItemAtPosition(ITEMS_PER_PAGE, swipeDown())); verifyItemSnappedToListTop(); }
public void scrollToPosition(int position) { RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager(); if (layoutManager == null) { return; } RecyclerView.SmoothScroller smoothScroller = mSnapHelper.createScroller(layoutManager); smoothScroller.setTargetPosition(position); layoutManager.startSmoothScroll(smoothScroller); mHandler.post(mUpdatePaginationRunnable); }
PagedListView extends FrameLayout { public void scrollToPosition(int position) { RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager(); if (layoutManager == null) { return; } RecyclerView.SmoothScroller smoothScroller = mSnapHelper.createScroller(layoutManager); smoothScroller.setTargetPosition(position); layoutManager.startSmoothScroll(smoothScroller); mHandler.post(mUpdatePaginationRunnable); } }
PagedListView extends FrameLayout { public void scrollToPosition(int position) { RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager(); if (layoutManager == null) { return; } RecyclerView.SmoothScroller smoothScroller = mSnapHelper.createScroller(layoutManager); smoothScroller.setTargetPosition(position); layoutManager.startSmoothScroll(smoothScroller); mHandler.post(mUpdatePaginationRunnable); } PagedListView(Context context);  PagedListView(Context context, AttributeSet attrs);  PagedListView(Context context, AttributeSet attrs, int defStyleAttrs);  PagedListView(Context context, AttributeSet attrs, int defStyleAttrs, int defStyleRes); }
PagedListView extends FrameLayout { public void scrollToPosition(int position) { RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager(); if (layoutManager == null) { return; } RecyclerView.SmoothScroller smoothScroller = mSnapHelper.createScroller(layoutManager); smoothScroller.setTargetPosition(position); layoutManager.startSmoothScroll(smoothScroller); mHandler.post(mUpdatePaginationRunnable); } PagedListView(Context context);  PagedListView(Context context, AttributeSet attrs);  PagedListView(Context context, AttributeSet attrs, int defStyleAttrs);  PagedListView(Context context, AttributeSet attrs, int defStyleAttrs, int defStyleRes); int positionOf(@Nullable View v); void setGutter(@Gutter int gutter); void setGutterSize(int gutterSize); void setScrollBarContainerWidth(int width); void setScrollBarTopMargin(int topMargin); void setListContentTopOffset(int offset); @NonNull RecyclerView getRecyclerView(); void scrollToPosition(int position); void snapToPosition(int position); void setUpButtonIcon(Drawable icon); void setDownButtonIcon(Drawable icon); void setAdapter(
            @NonNull RecyclerView.Adapter<? extends RecyclerView.ViewHolder> adapter); void setDividerVisibilityManager(DividerVisibilityManager dvm); @Nullable @SuppressWarnings("unchecked") RecyclerView.Adapter<? extends RecyclerView.ViewHolder> getAdapter(); void setMaxPages(int maxPages); int getMaxPages(); int getRowsPerPage(); void resetMaxPages(); void addItemDecoration(@NonNull RecyclerView.ItemDecoration decor); void removeItemDecoration(@NonNull RecyclerView.ItemDecoration decor); void setItemSpacing(int itemSpacing); void setScrollbarColor(@ColorRes int color); void resetScrollbarColor(); void addOnItemTouchListener(@NonNull RecyclerView.OnItemTouchListener touchListener); void removeOnItemTouchListener(@NonNull RecyclerView.OnItemTouchListener touchListener); void setDayNightStyle(@DayNightStyle int dayNightStyle); void setOnScrollListener(OnScrollListener listener); int getPage(int position); void pageUp(); void pageDown(); void setDefaultMaxPages(int newDefault); @Override void onLayout(boolean changed, int left, int top, int right, int bottom); boolean isAtStart(); boolean isAtEnd(); @Override Parcelable onSaveInstanceState(); @Override void onRestoreInstanceState(Parcelable state); }
PagedListView extends FrameLayout { public void scrollToPosition(int position) { RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager(); if (layoutManager == null) { return; } RecyclerView.SmoothScroller smoothScroller = mSnapHelper.createScroller(layoutManager); smoothScroller.setTargetPosition(position); layoutManager.startSmoothScroll(smoothScroller); mHandler.post(mUpdatePaginationRunnable); } PagedListView(Context context);  PagedListView(Context context, AttributeSet attrs);  PagedListView(Context context, AttributeSet attrs, int defStyleAttrs);  PagedListView(Context context, AttributeSet attrs, int defStyleAttrs, int defStyleRes); int positionOf(@Nullable View v); void setGutter(@Gutter int gutter); void setGutterSize(int gutterSize); void setScrollBarContainerWidth(int width); void setScrollBarTopMargin(int topMargin); void setListContentTopOffset(int offset); @NonNull RecyclerView getRecyclerView(); void scrollToPosition(int position); void snapToPosition(int position); void setUpButtonIcon(Drawable icon); void setDownButtonIcon(Drawable icon); void setAdapter(
            @NonNull RecyclerView.Adapter<? extends RecyclerView.ViewHolder> adapter); void setDividerVisibilityManager(DividerVisibilityManager dvm); @Nullable @SuppressWarnings("unchecked") RecyclerView.Adapter<? extends RecyclerView.ViewHolder> getAdapter(); void setMaxPages(int maxPages); int getMaxPages(); int getRowsPerPage(); void resetMaxPages(); void addItemDecoration(@NonNull RecyclerView.ItemDecoration decor); void removeItemDecoration(@NonNull RecyclerView.ItemDecoration decor); void setItemSpacing(int itemSpacing); void setScrollbarColor(@ColorRes int color); void resetScrollbarColor(); void addOnItemTouchListener(@NonNull RecyclerView.OnItemTouchListener touchListener); void removeOnItemTouchListener(@NonNull RecyclerView.OnItemTouchListener touchListener); void setDayNightStyle(@DayNightStyle int dayNightStyle); void setOnScrollListener(OnScrollListener listener); int getPage(int position); void pageUp(); void pageDown(); void setDefaultMaxPages(int newDefault); @Override void onLayout(boolean changed, int left, int top, int right, int bottom); boolean isAtStart(); boolean isAtEnd(); @Override Parcelable onSaveInstanceState(); @Override void onRestoreInstanceState(Parcelable state); static final int DEFAULT_MAX_CLICKS; static final int UNLIMITED_PAGES; }