RecyclerView decorator adding extra padding on refresh

后端 未结 8 2062
轻奢々
轻奢々 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:08

    This is happening because we are trying to add itemDecorator to the recycler view which already have itemDecorator added to it, check first if its already there then don't add again

    if (0 == recyclerview.getItemDecorationCount()) {
    recyclerview.addItemDecoration(new DividerItemDecoration(ContextCompat.getDrawable(getActivity(), R.drawable.divider)));
    }
    

    This 0 will be the number of itemDecorator we have in recycler view, most of the time it'll be 0.

提交回复
热议问题