Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change output Rect color in RecyclerView ItemDecoration - Android

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 ?

like image 714
Sayed Jalil Hassan Avatar asked May 13 '15 13:05

Sayed Jalil Hassan


1 Answers

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

like image 155
Nicolas Duponchel Avatar answered Oct 19 '22 06:10

Nicolas Duponchel