美文网首页
recyclerview的滚动检测

recyclerview的滚动检测

作者: 名字_都被占了 | 来源:发表于2018-09-28 09:45 被阅读0次

    已记录

     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的滚动检测

          本文链接:https://www.haomeiwen.com/subject/coeuoftx.html