Reputation: 4049
I have a RecyclerView. For graphical design reason, this recycler own a padding. For some item of the recyclerview, I need to not have this padding.
So my intension was to define a negative margin for the itemDecorator, as the following :
class MarginDecoration extends RecyclerView.ItemDecoration {
private int marge_small_border;
public MarginDecoration(Context context) {
marge_small_border = context.getResources().getDimensionPixelSize(R.dimen.marge_small_border);
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.set(-marge_small_border, 0, -marge_small_border, 0);
}
}
This is not working !
EDIT :
3. My need: (the right picture)
Here is what I want to do
1. The Left Picture
Orange is the FrameLayout that hold the RecyclerView, so with horizontal padding.
My RecyclerView, has a header, a picture and then items that are render 2 by rows.
My requirement are : - to have the header fulling the screen (no padding on horizontal dimension) => do not see the orange at image/header level - to have same dimensions for every space between non-header items.
2. The solution I have today, with decorators
I put a decorator of every items of Xdp I put a padding on the container frame of Xdp => I have 2Xdp for every non-header items.
Now, I should remove the padding of header, so add a decorator of -Xdp.
QUESTION:
How do that ?
Any other solution are also welcome.
EDIT :
Making a decorator of item depending on the item position is not really feasable, because, in the list, then can appear label (full with). Addition impair number of item in blocks (between labels) will make the item space before the label void.
Upvotes: 3
Views: 2188
Reputation: 2494
I had a similar issue. I don't know if you still need help with this but I did the following:
add padding to the recycler view
set the android:clipToPadding
and android:clipChildren
flags of the recycler view to false
add negative padding to the header item equal to the margin given to the RV
(optional) if you want to make the size of the middle divider and sides equal, give half the padding to the list items and half to the recyclerView as above
Upvotes: 4