how to show/hide FAB on scroll Recycler view with coordinator parent

前端 未结 5 865
轻奢々
轻奢々 2021-02-04 11:41

I have an activity with coordinator layout.inside activity there is a fragment with Recycler view and float button.how can I show/hide float button when Scroll Recycler view and

5条回答
  •  名媛妹妹
    2021-02-04 12:06

    This code works just fine:

     mRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
                    @Override
                    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                        if(dy > 0){
                            mFab.hide();
                        } else{
                            mFab.show();
                        }
    
                        super.onScrolled(recyclerView, dx, dy);
                    }
                });
    

    You cannot do:

    app:layout_anchor="@id/listView"
    app:layout_anchorGravity="bottom|end"
    

    Look here:

    There is no support built-in for CoordinatorLayout to work with ListView according to this Google post.

提交回复
热议问题