@Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = mLinearLayoutManager.getItemCount();
    firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();

    if (loading) {
      if (totalItemCount > previousTotal) {
        loading = false;
        previousTotal = totalItemCount;
      }
    }
    if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
      // End has been reached

      // Do something
      current_page++;

      onLoadMore(current_page);

      loading = true;
    }
  }
 @Override
 public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
   if (dy > 0
       && viewListLayoutManager.findLastVisibleItemPosition()
           == viewListLayoutManager.getItemCount() - 1) {
     presenter.onScrolledToBottom();
   }
 }
 public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
   super.onScrolled(recyclerView, dx, dy);
   int lastVisibleItem = mLayoutManager.findLastVisibleItemPosition();
   int totalItemCount = mLayoutManager.getItemCount();
   if (lastVisibleItem >= totalItemCount - 4 && dy > 0) {
     if (mState == STATE_NONE && mAdapter != null && mAdapter.getDataSize() > 0) {
       loadMore();
     }
   }
 };
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    if (mLinearLayoutManager == null) {
      mLinearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    }

    firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();
    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = mLinearLayoutManager.getItemCount();

    if (infiniteScrollingEnabled) {
      if (loading) {
        if (totalItemCount > previousTotal) {
          loading = false;
          previousTotal = totalItemCount;
        }
      }

      if (!loading && (totalItemCount - visibleItemCount <= firstVisibleItem + visibleThreshold)) {
        // End has been reached
        // do something
        onLoadMore();
        loading = true;
      }
    }

    if (firstVisibleItem == 0) {
      if (!controlsVisible) {
        onScrollUp();
        controlsVisible = true;
      }

      return;
    }

    if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
      onScrollDown();
      controlsVisible = false;
      scrolledDistance = 0;
    } else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) {
      onScrollUp();
      controlsVisible = true;
      scrolledDistance = 0;
    }

    if ((controlsVisible && dy > 0) || (!controlsVisible && dy < 0)) {
      scrolledDistance += dy;
    }
  }
Exemplo n.º 5
0
 @Override
 public void onScrollStateChanged(
     android.support.v7.widget.RecyclerView recyclerView, int newState) {
   LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
   if (newState == RecyclerView.SCROLL_STATE_IDLE
       && layoutManager.findLastVisibleItemPosition() + 1
           == layoutManager.getItemCount()) { // 如果滚动到最后一行
     if (autoLoadMore) {
       if (hasMoreData) {
         if (!isLoading()) {
           // 如果网络可以用
           if (needCheckNetwork && !NetworkUtils.hasNetwork(context)) {
             mLoadMoreView.showFail();
           } else {
             loadMore();
           }
         }
       }
     }
   }
 }