@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (!isHeader(view, parent)) return; outRect.left = sidePaddingPixels; outRect.right = sidePaddingPixels; }
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (!isInset(view, parent)) return; GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams) view.getLayoutParams(); GridLayoutManager gridLayoutManager = (GridLayoutManager) parent.getLayoutManager(); float spanSize = layoutParams.getSpanSize(); float totalSpanSize = gridLayoutManager.getSpanCount(); float n = totalSpanSize / spanSize; // num columns float c = layoutParams.getSpanIndex() / spanSize; // column index float leftPadding = padding * ((n - c) / n); float rightPadding = padding * ((c + 1) / n); outRect.left = (int) leftPadding; outRect.right = (int) rightPadding; outRect.bottom = padding; }
private Group makeCarouselGroup() { CarouselItemDecoration carouselDecoration = new CarouselItemDecoration(gray, betweenPadding); GroupAdapter carouselAdapter = new GroupAdapter(); for (int i = 0; i < 10; i++) { carouselAdapter.add(new CarouselCardItem(rainbow200[i])); } return new CarouselGroup(carouselDecoration, carouselAdapter); }
recyclerView.addItemDecoration(new HeaderItemDecoration(gray, betweenPadding)); recyclerView.addItemDecoration(new InsetItemDecoration(gray, betweenPadding)); recyclerView.addItemDecoration(new DebugItemDecoration(this)); recyclerView.setAdapter(groupAdapter); recyclerView.addOnScrollListener(new InfiniteScrollListener(layoutManager) {
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { for (int i = 0; i < parent.getChildCount(); i++) { View child = parent.getChildAt(i); if (!isHeader(child, parent)) continue; RecyclerView.LayoutManager lm = parent.getLayoutManager(); float top = lm.getDecoratedTop(child) + child.getTranslationY(); float bottom = lm.getDecoratedBottom(child) + child.getTranslationY(); if (i == parent.getChildCount() - 1) { // Draw to bottom if last item bottom = Math.max(parent.getHeight(), bottom); } float right = lm.getDecoratedRight(child) + child.getTranslationX(); float left = lm.getDecoratedLeft(child) + child.getTranslationX(); c.drawRect(left, top, right, bottom, paint); } } }
for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); if (!isInset(child, parent)) continue;