美文网首页
RecycleView 监听

RecycleView 监听

作者: 满船清梦___ | 来源:发表于2017-12-08 16:19 被阅读9次
    recycle.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == RecyclerView.SCROLL_STATE_IDLE && adapter != null && lastVisibleItem + 2 == adapter.getItemCount()) {
                presenter.loadMoreData();
            }
            if (newState == RecyclerView.SCROLL_STATE_IDLE && adapter != null) {
                Log.d(TAG, "onScrollStateChanged: " + lastVisibleItem + "--" + linearLayoutManager.findFirstCompletelyVisibleItemPosition() + "--" + linearLayoutManager.findFirstVisibleItemPosition());
                //无法向上滑动表示到达最顶
                if (!recyclerView.canScrollVertically(-1)) {
                    CommonUtils.keyBoard(edit, "close");
                }
                /*else if (!recyclerView.canScrollVertically(1)) {
                    onScrolledToBottom();
                }*/
            }
        }
    
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            // 当dy < 0; 表示向上滑动
            lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
        }
    });
    

    相关文章

      网友评论

          本文标题:RecycleView 监听

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