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

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

    Solution in Kotlin

    recycler_view = findViewById(R.id.recycler_view)
    
            recycler_view.addOnScrollListener(object : RecyclerView.OnScrollListener(){
                override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
                    if(dy > 0){
                        fab.hide();
                    } else{
                        fab.show();
                    }
                    super.onScrolled(recyclerView, dx, dy)
    
                }
            })
    

提交回复
热议问题