@Test public void setItemSpacing() throws Throwable { final int itemCount = 3; setUpPagedListView(itemCount ); final View[] views = new View[itemCount]; mActivityRule.runOnUiThread(() -> { for (int i = 0; i < mRecyclerViewLayoutManager.getChildCount(); i++) { views[i] = mRecyclerViewLayoutManager.getChildAt(i); } }); for (int i = 0; i < itemCount - 1; i++) { assertThat(views[i + 1].getTop() - views[i].getBottom(), is(equalTo(0))); } final int itemSpacing = 10; mActivityRule.runOnUiThread(() -> { mPagedListView.setItemSpacing(itemSpacing); }); mActivityRule.runOnUiThread(() -> { for (int i = 0; i < mRecyclerViewLayoutManager.getChildCount(); i++) { views[i] = mRecyclerViewLayoutManager.getChildAt(i); } }); for (int i = 0; i < itemCount - 1; i++) { assertThat(views[i + 1].getTop() - views[i].getBottom(), is(equalTo(itemSpacing))); } mActivityRule.runOnUiThread(() -> { mPagedListView.setItemSpacing(0); }); mActivityRule.runOnUiThread(() -> { for (int i = 0; i < mRecyclerViewLayoutManager.getChildCount(); i++) { views[i] = mRecyclerViewLayoutManager.getChildAt(i); } }); for (int i = 0; i < itemCount - 1; i++) { assertThat(views[i + 1].getTop() - views[i].getBottom(), is(equalTo(0))); } }
public void setItemSpacing(int itemSpacing) { ItemSpacingDecoration existing = null; for (int i = 0, count = mRecyclerView.getItemDecorationCount(); i < count; i++) { RecyclerView.ItemDecoration itemDecoration = mRecyclerView.getItemDecorationAt(i); if (itemDecoration instanceof ItemSpacingDecoration) { existing = (ItemSpacingDecoration) itemDecoration; break; } } if (itemSpacing == 0 && existing != null) { mRecyclerView.removeItemDecoration(existing); } else if (existing == null) { mRecyclerView.addItemDecoration(new ItemSpacingDecoration(itemSpacing)); } else { existing.setItemSpacing(itemSpacing); } mRecyclerView.invalidateItemDecorations(); }
PagedListView extends FrameLayout { public void setItemSpacing(int itemSpacing) { ItemSpacingDecoration existing = null; for (int i = 0, count = mRecyclerView.getItemDecorationCount(); i < count; i++) { RecyclerView.ItemDecoration itemDecoration = mRecyclerView.getItemDecorationAt(i); if (itemDecoration instanceof ItemSpacingDecoration) { existing = (ItemSpacingDecoration) itemDecoration; break; } } if (itemSpacing == 0 && existing != null) { mRecyclerView.removeItemDecoration(existing); } else if (existing == null) { mRecyclerView.addItemDecoration(new ItemSpacingDecoration(itemSpacing)); } else { existing.setItemSpacing(itemSpacing); } mRecyclerView.invalidateItemDecorations(); } }
PagedListView extends FrameLayout { public void setItemSpacing(int itemSpacing) { ItemSpacingDecoration existing = null; for (int i = 0, count = mRecyclerView.getItemDecorationCount(); i < count; i++) { RecyclerView.ItemDecoration itemDecoration = mRecyclerView.getItemDecorationAt(i); if (itemDecoration instanceof ItemSpacingDecoration) { existing = (ItemSpacingDecoration) itemDecoration; break; } } if (itemSpacing == 0 && existing != null) { mRecyclerView.removeItemDecoration(existing); } else if (existing == null) { mRecyclerView.addItemDecoration(new ItemSpacingDecoration(itemSpacing)); } else { existing.setItemSpacing(itemSpacing); } mRecyclerView.invalidateItemDecorations(); } 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 setItemSpacing(int itemSpacing) { ItemSpacingDecoration existing = null; for (int i = 0, count = mRecyclerView.getItemDecorationCount(); i < count; i++) { RecyclerView.ItemDecoration itemDecoration = mRecyclerView.getItemDecorationAt(i); if (itemDecoration instanceof ItemSpacingDecoration) { existing = (ItemSpacingDecoration) itemDecoration; break; } } if (itemSpacing == 0 && existing != null) { mRecyclerView.removeItemDecoration(existing); } else if (existing == null) { mRecyclerView.addItemDecoration(new ItemSpacingDecoration(itemSpacing)); } else { existing.setItemSpacing(itemSpacing); } mRecyclerView.invalidateItemDecorations(); } 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 setItemSpacing(int itemSpacing) { ItemSpacingDecoration existing = null; for (int i = 0, count = mRecyclerView.getItemDecorationCount(); i < count; i++) { RecyclerView.ItemDecoration itemDecoration = mRecyclerView.getItemDecorationAt(i); if (itemDecoration instanceof ItemSpacingDecoration) { existing = (ItemSpacingDecoration) itemDecoration; break; } } if (itemSpacing == 0 && existing != null) { mRecyclerView.removeItemDecoration(existing); } else if (existing == null) { mRecyclerView.addItemDecoration(new ItemSpacingDecoration(itemSpacing)); } else { existing.setItemSpacing(itemSpacing); } mRecyclerView.invalidateItemDecorations(); } 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; }