RecyclerView decorator adding extra padding on refresh

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

    Apparently you are adding various decorations. I was having the same problem. What I did here and that worked out was:

    1º - Declare the decoration before the onCreate () method:

    public StickyHeaderDecoration mDecor;
    public MyAdapterPinned MyAdapterPinned;
    

    2º - Then I created a method that creates and populates my recycleview. In this method I check if I have already called mDecor. If so, I remove it. Otherwise, I create it. The code looks like this:

    public void createRecyclerView(){
        //hide layout com progress
        hideLayoutProgressFull();
    
        LinearLayoutManager mLayoutManager = new 
        LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(mLayoutManager);
    
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    
        myAdapterPinned = new MyAdapterPinned(getContext(), mList);
    
        recyclerView.setAdapter(myAdapterPinned);
    
        if (mDecor != null)
            recyclerView.removeItemDecoration(mDecor);
    
        mDecor = new StickyHeaderDecoration(myAdapterPinned);
        recyclerView.addItemDecoration(mDecor);
    
        //hide progressDialog
        hideProgress();
    }    
    

    NOTE: I am using an adapter that sets the title to each change but you can not interfere with the result. You can use your ordinary adapter. It worked for me. I hope it works for you too;

提交回复
热议问题