Yes, you can.
If you draw the decoration yourself, you can distinguish between different types of views in getItemOffsets and onDraw , referring to the same method on the adapter, like this:
Using this, you can draw your decoration only for selected species. Having access to getLeft() and getRight() , this code supports GridLayout , as well as LinearLayout , in order to support horizontal alignment, the drawing should be done on the right side, using the same approach.
In the end, you will create a jewelry similar to the following:
public class DividerDecoration extends RecyclerView.ItemDecoration { private final Paint mPaint; private int mHeightDp; public DividerDecoration(Context context) { this(context, Color.argb((int) (255 * 0.2), 0, 0, 0), 1f); } public DividerDecoration(Context context, int color, float heightDp) { mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(color); mHeightDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, heightDp, context.getResources().getDisplayMetrics()); } @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); int viewType = parent.getAdapter().getItemViewType(position); if (viewType = MY_VIEW_TYPE) { outRect.set(0, 0, 0, mHeightDp); } else { outRect.setEmpty(); } } @Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { for (int i = 0; i < parent.getChildCount(); i++) { View view = parent.getChildAt(i); int position = parent.getChildAdapterPosition(view); int viewType = parent.getAdapter().getItemViewType(position); if (viewType = MY_VIEW_TYPE) { c.drawRect(view.getLeft(), view.getBottom(), view.getRight(), view.getBottom() + mHeightDp, mPaint); } } } }
There is a similar sample on GitHub with a demo project that will not draw before or after the headers or at the very end.