RecyclerView decorator adding extra padding on refresh

后端 未结 8 2063
轻奢々
轻奢々 2021-02-01 17:42

So, I\'m facing a weird problem while implementing RecyclerView in my project. I have a custom decorator to implement a consistent top and bottom padding and a rather different

8条回答
  •  独厮守ぢ
    2021-02-01 18:06

    I was facing the same issue, the best solution is to make your item decoration while your are initializing your layout manager in the view holder , this resolves the problem you are facing example

    public class GridViewHolder extends ViewHolder {
    
        RecyclerView grid_list;
    
        public GridViewHolder(View v) {
            super(v);
            this.grid_list = (RecyclerView) v.findViewById(R.id.home_screen_item_grid_recycler_view);
            if (grid_list.getLayoutManager() == null) {
                RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(context, 4);
                grid_list.setLayoutManager(mLayoutManager);
                grid_list.addItemDecoration(new GridSpacingItemDecoration(4, 3, false));
            }
        }
    }
    

提交回复
热议问题