xiaofeng-han / AndroidLibs

GNU General Public License v3.0
183 stars 42 forks source link

The margin of child item in recyclerview is not work. #21

Open KimBunhong opened 7 years ago

KimBunhong commented 7 years ago

I tried to set margin to child item but its not work. How can I do? screenshot_2017-07-14-15-30-24

mihakrajnc commented 7 years ago

Same issue here, setting a margin to the root of an item won't work.

Workaround: Put a FrameLayout around your item, and keep the margin on the child, or remove the margin and add padding to the FrameLayout.

illia-kramarenko commented 6 years ago

@KimBunhong, @mihakrajnc Or you can use something like this:

final int space = getResources().getDimensionPixelSize(R.dimen.item_margin);

recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.bottom = space;
        outRect.right = space;
        outRect.left = space;
        outRect.top = space;
    }
});
KhanStan99 commented 5 years ago

@illia-kramarenko Thanks! It worked.

Is this a bug in library? if not the this issue should be closed.