FloatingActionButton向下滑动隐藏向上滑动显示

beauty_recycle.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
        if (dy > 0 && floatingActionButton.getVisibility() == View.VISIBLE){
            floatingActionButton.hide();
        }else if (dy < 0 && floatingActionButton.getVisibility() != View.VISIBLE){
            floatingActionButton.show();
        }
    }

});

给RecycleView设置监听。

 

滑动置顶

fab_data.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        re_data.smoothScrollToPosition(0);
    }
});

你可能感兴趣的:(FloatingActionButton向下滑动隐藏向上滑动显示)