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

前端 未结 5 859
轻奢々
轻奢々 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:22

    I modified Leondro's method such that the FAB will hide when there's scrolling and show when the scrolling stops.

    scrollListener = new RecyclerView.OnScrollListener() {  
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            switch (newState) {
                case RecyclerView.SCROLL_STATE_IDLE:
                    fab.show();
                    break;
                default:
                    fab.hide();
                    break;
            }
            super.onScrollStateChanged(recyclerView, newState);
        }
    }; 
    
    rv.clearOnScrollListeners();
    rv.addOnScrollListener(scrollListener);
    

提交回复
热议问题