I have this method in ItemDecoration class for recyclerView -
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.left = space;
outRect.right = space;
outRect.bottom = space;
// Add top margin only for the first item to avoid double space between items
if(parent.getChildPosition(view) == 0)
outRect.top = space;
}
Is there any way to change the color of output outRect like redrawing it or something ?
You could have a look at ItemDecoration
documentation.
2 main things to know :
getItemOffsets(...)
will allow you to determine the space between your items with provided rect in params.onDraw(...)
will allow you to draw whatever you can in that space you set in getItemOffsets(...)
. You can use a Drawable
or simple provided Canvas
, etc. If it's still not clear enough, check this article. I explain how to build your custom ItemDecoration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With