recyclerview的滚动检测

已记录

 recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == 0) {//当newState == 0时,表示recyclerView已经停止滚动了
                    if (upgundong) {
                        linear1.animate().alpha(1).scaleY(1).start();
                        linear.animate().alpha(1).scaleY(1).start();
                        linear1.setVisibility(View.VISIBLE);
                        linear.setVisibility(View.VISIBLE);
                        tu10.setVisibility(View.GONE);
                        tu11.setVisibility(View.VISIBLE);
                    } else {
                        linear1.animate().alpha(0).scaleY(0).withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                linear1.setVisibility(View.GONE);
                            }
                        }).start();
                        linear.animate().alpha(0).scaleY(0).withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                linear.setVisibility(View.GONE);
                            }
                        }).start();
                        tu10.setVisibility(View.GONE);
                        tu11.setVisibility(View.VISIBLE);
                    }
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                //当执行完onScrolled方法后,系统会执行onScrollStateChanged方法
                super.onScrolled(recyclerView, dx, dy);
                if (!recyclerView.canScrollVertically(-1)) {
                    upgundong = true;
                    Log.d("qwer", "到顶了" + dy);
                } else if (!recyclerView.canScrollVertically(1)) {
                    upgundong = false;
                    Log.d("qwer", "到底了" + dy);
                } else if (dy < 0) {
                    upgundong = true;
                    Log.d("qwer", "向上划" + dy);
                } else if (dy > 0) {
                    upgundong = false;
                    Log.d("qwer", "向下划" + dy);
                }
            }
        });

你可能感兴趣的:(recyclerview的滚动检测)