Java Code Examples for android.support.v7.widget.LinearLayoutManager#getItemCount()

The following examples show how to use android.support.v7.widget.LinearLayoutManager#getItemCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LMRecyclerView.java    From WanAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 滑动监听
 * @param recyclerView
 * @param dx
 * @param dy
 */
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    LayoutManager layoutManager = recyclerView.getLayoutManager();

    if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayout = (LinearLayoutManager) layoutManager;
        int mLastChildPosition = linearLayout.findLastVisibleItemPosition();
        int itemTotalCount = linearLayout.getItemCount();
        View lastChildView = linearLayout.getChildAt(linearLayout.getChildCount() - 1);
        int lastChildBottom = lastChildView.getBottom();
        int recyclerBottom = getBottom();
        if (mLastChildPosition == itemTotalCount - 1 && lastChildBottom == recyclerBottom) {
            if (isCanLoadMore && listener != null) {
                //业务代码
                listener.loadMore();
            }
        }
    }
}
 
Example 2
Source File: FragmentStatusList.java    From Rumble with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    LinearLayoutManager mLayoutManager = (LinearLayoutManager)recyclerView.getLayoutManager();
    int visibleItemCount = mLayoutManager.getChildCount();
    int totalItemCount = mLayoutManager.getItemCount();
    int pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();
    if ( (visibleItemCount + pastVisiblesItems) >= totalItemCount) {
        if((!loadingMore) && (!noMoreStatusToLoad)) {
            PushStatus status = statusRecyclerAdapter.getLastItem();
            if(status == null)
                return;
            refreshStatuses(status.getTimeOfArrival(),-1);
        }
    }

    /*
     * since design version > 22, I can't use misc.ScrollAwareFABBehavior because
     * hide() makes the view to GONE and thus doesn't trigger the onNestedScroll
     * So instead we use the Recycler Scroll to trigger the hide/show.
     */
    if (dy > 0)
        composeFAB.hide();
    else if (dy < 0)
        composeFAB.show();
}
 
Example 3
Source File: RecyclerRefreshLayout.java    From umeng_community_android with MIT License 6 votes vote down vote up
/**
 * 判断是否到了最底部
 */
private boolean isBottom(int dy) {
    // 已经到最后一项且可见的第一项>0
    // if (mRecyclerView != null && mRecyclerView.getAdapter() != null) {
    // int childCount = mRecyclerView.getAdapter().getCount();
    // return childCount > 1
    // && mRecyclerView.getLastVisiblePosition() == childCount - 1;
    // }

    LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
    int lastVisibleItem = layoutManager.findLastVisibleItemPosition();
    int totalItemCount = layoutManager.getItemCount();
    // dy>0 表示向下滑动
    if (lastVisibleItem >= totalItemCount - 4 && dy > 0) {
        return true;
    }
    return false;
}
 
Example 4
Source File: StargazerListActivityViewModel.java    From Anago with Apache License 2.0 6 votes vote down vote up
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (dy > 0) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        int visible = layoutManager.getChildCount();
        int total = layoutManager.getItemCount();
        int first = layoutManager.findFirstVisibleItemPosition();
        if (visible + first >= total) {
            Timber.v("Scroll End");
            if (!loadingMore) {
                Timber.v("Start loading more");
                loadingMore = true;
                load();
            }
        }
    }
}
 
Example 5
Source File: OnLoadMoreListener.java    From Toutiao with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();

        itemCount = layoutManager.getItemCount();
        lastPosition = layoutManager.findLastCompletelyVisibleItemPosition();
    } else {
        Log.e("OnLoadMoreListener", "The OnLoadMoreListener only support LinearLayoutManager");
        return;
    }

    if (lastItemCount != itemCount && lastPosition == itemCount - 1) {
        lastItemCount = itemCount;
        this.onLoadMore();
    }
}
 
Example 6
Source File: ViewToImageUtil.java    From ViewToImage with Apache License 2.0 6 votes vote down vote up
/**
 * RecyclerView转换成bitmap
 *
 * @param recyclerView
 * @return
 */
public static List<BitmapWithHeight> getWholeRecyclerViewItemsToBitmap(final RecyclerView recyclerView) {
    List<BitmapWithHeight> list = new ArrayList<>();
    if (recyclerView == null || recyclerView.getAdapter() == null) {
        return list;
    }

    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
        if (manager.getOrientation() == LinearLayoutManager.VERTICAL) {
            int count = manager.getItemCount();
            LogUtils.w(count + "");
            for (int i = 0; i < count; i++) {
                View childView = manager.findViewByPosition(i);
                // TODO: 1/25/16  childView不可见部分为null,无法截长图
                if (childView != null) {
                    list.add(getSimpleViewToBitmap(childView, recyclerView.getMeasuredWidth()));
                }
            }
        } else {
            list.add(getSimpleViewToBitmap(recyclerView, recyclerView.getMeasuredWidth()));
        }
    }

    return list;
}
 
Example 7
Source File: LoadMoreRecyclerView.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    LoadMoreRecyclerView view = (LoadMoreRecyclerView) recyclerView;
    onLoadMoreListener onLoadMoreListener = view.getOnLoadMoreListener();

    onLoadMoreListener.onScrolled(recyclerView, dx, dy);

    //if scroll to bottom
    LinearLayoutManager layoutManager = (LinearLayoutManager) view.getLayoutManager();
    int lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition();
    int itemCount = layoutManager.getItemCount();
    if (lastVisibleItem >= itemCount - 1 && !view.getLoadingMore()) {
        onLoadMoreListener.onLoadMore();
        L.i(TAG, "load more: lastVisibleItem = " + lastVisibleItem + ", itemCount " + itemCount);
    } else {
        super.onScrolled(recyclerView, dx, dy);
    }
}
 
Example 8
Source File: OnLoadMoreListener.java    From MiPushFramework with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();

        itemCount = layoutManager.getItemCount();
        lastPosition = layoutManager.findLastCompletelyVisibleItemPosition();
    } else {
        Log.e("OnLoadMoreListener", "The OnLoadMoreListener only support LinearLayoutManager");
        return;
    }

    if (lastItemCount != itemCount && (lastPosition > itemCount - 3)) {
        lastItemCount = itemCount;
        this.onLoadMore();
    }
}
 
Example 9
Source File: LMRecyclerView.java    From gank with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public void onScrollStateChanged(int state) {
       /* LinearLayoutManager mLayoutManager = (LinearLayoutManager) getLayoutManager();
        int lastVisibleItemPosition = 0;
        int totalItemCount = 0;
        if (mLayoutManager instanceof LinearLayoutManager) {
            if (state == RecyclerView.SCROLL_STATE_IDLE) {
                lastVisibleItemPosition = mLayoutManager.findLastCompletelyVisibleItemPosition();
                totalItemCount = mLayoutManager.getItemCount();
                if (lastVisibleItemPosition == (totalItemCount - 1) && isScrollingToBottom) {
                    if (listener != null)
                        listener.loadMore();
                }
            }

        } else if (mLayoutManager instanceof GridLayoutManager) {
            if (state == RecyclerView.SCROLL_STATE_IDLE) {
                lastVisibleItemPosition = mLayoutManager.findLastCompletelyVisibleItemPosition();
                totalItemCount = mLayoutManager.getItemCount();
                if (lastVisibleItemPosition == (totalItemCount - 1) && isScrollingToBottom) {
                    if (listener != null)
                        listener.loadMore();
                }
            }
        }
*/
       LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
        if (state == RecyclerView.SCROLL_STATE_IDLE) {
            int lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition();
            int totalItemCount = layoutManager.getItemCount();
            if (lastVisibleItem == (totalItemCount - 1) && isScrollingToBottom) {
                if (listener != null)
                    listener.loadMore();
            }
        }
    }
 
Example 10
Source File: BaseRecyclerViewModel.java    From Android-MVVMFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    int lastVisibleItem = layoutManager.findLastVisibleItemPosition();
    int totalItemCount = layoutManager.getItemCount();
    //lastVisibleItem >= totalItemCount - 1 表示剩下1个item自动加载
    // dy>0 表示向下滑动
    if (lastVisibleItem >= totalItemCount - 1 && dy > 0) {
        onListLoadMore();
    }
}
 
Example 11
Source File: MultiFuncRecyclerView.java    From TestChat with Apache License 2.0 5 votes vote down vote up
private void processLoadMoreData() {
                LinearLayoutManager linearLayoutManager = (LinearLayoutManager) display.getLayoutManager();
                int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();
                int totalCount = linearLayoutManager.getItemCount();
                int visibleCount = linearLayoutManager.getChildCount();
//                这里分两种情况,当缓慢滑动的时候,边滑动边加载,没有接触到底部。当如果快速滑动的时候,还没加载完就滑动到底部
                if ((firstVisibleItemPosition + visibleCount >= totalCount) && !isLoading && totalCount != 1) {
                        LogUtil.e("底部加载拉");
                        if (mOnMoreDataLoadListener != null) {
                                isLoading = true;
                                moreLoadView.setVisibility(VISIBLE);
                                mOnMoreDataLoadListener.onMoreDataLoad(totalCount, firstVisibleItemPosition);
                        }
                }
        }
 
Example 12
Source File: ExcelPanel.java    From excelPanel with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    amountAxisX += dx;
    fastScrollTo(amountAxisX, mRecyclerView, loadingViewWidth, hasHeader);
    fastScrollTo(amountAxisX, topRecyclerView, loadingViewWidth, hasHeader);
    if (dx == 0 && dy == 0) {
        return;
    }
    if (mScrollListeners != null) {
        for (int i = mScrollListeners.size() - 1; i >= 0; i--) {
            OnScrollListener listener = mScrollListeners.get(i);
            if (listener != null) {
                listener.onScrolled(ExcelPanel.this, dx, dy);
            }
        }
    }
    LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
    int visibleItemCount = recyclerView.getChildCount();
    int totalItemCount = manager.getItemCount();
    int firstVisibleItem = manager.findFirstVisibleItemPosition();
    if (totalItemCount - visibleItemCount <= firstVisibleItem && onLoadMoreListener != null && hasFooter) {
        onLoadMoreListener.onLoadMore();
    }
    if (amountAxisX < loadingViewWidth && onLoadMoreListener != null && hasHeader) {
        onLoadMoreListener.onLoadHistory();
    }
    if (((hasHeader && amountAxisX > loadingViewWidth) || (!hasHeader && amountAxisX > 0)) && dividerLineVisible) {
        dividerLine.setVisibility(VISIBLE);
    } else {
        dividerLine.setVisibility(GONE);
    }
}
 
Example 13
Source File: EndlessScrollListener.java    From BaseQuickAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {

    BaseQuickAdapter adapter = (BaseQuickAdapter) recyclerView.getAdapter();

    LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
    if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItemPosition + 1 == layoutManager.getItemCount() && adapter.isHasMore()) {
        //当已经滑到最后一条的时候
        adapter.isLoadingMore();
    }
}
 
Example 14
Source File: OnScrollToLastListener.java    From kaif-android with Apache License 2.0 5 votes vote down vote up
@Override
public final void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();

  int visibleItemCount = layoutManager.getChildCount();
  int totalItemCount = layoutManager.getItemCount();
  int pastVisibleItems = layoutManager.findFirstVisibleItemPosition();

  if ((visibleItemCount + pastVisibleItems) >= totalItemCount) {
    onScrollToLast();
  }
}
 
Example 15
Source File: GravitySnapHelper.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private boolean isAtEdgeOfList(LinearLayoutManager lm) {
    if ((!lm.getReverseLayout() && gravity == Gravity.START)
            || (lm.getReverseLayout() && gravity == Gravity.END)
            || (!lm.getReverseLayout() && gravity == Gravity.TOP)
            || (lm.getReverseLayout() && gravity == Gravity.BOTTOM)) {
        return lm.findLastCompletelyVisibleItemPosition() == lm.getItemCount() - 1;
    } else if (gravity == Gravity.CENTER) {
        return lm.findFirstCompletelyVisibleItemPosition() == 0
                || lm.findLastCompletelyVisibleItemPosition() == lm.getItemCount() - 1;
    } else {
        return lm.findFirstCompletelyVisibleItemPosition() == 0;
    }
}
 
Example 16
Source File: LMRecyclerView.java    From Gank.io with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onScrollStateChanged(int state) {
  LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
  if (state == RecyclerView.SCROLL_STATE_IDLE) {
    int lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition();
    int totalItemCount = layoutManager.getItemCount();
    if (lastVisibleItem == (totalItemCount - 1) && isScrollingToBottom) {
      if (listener != null)
        listener.loadMore();
    }
  }
}
 
Example 17
Source File: ViewAdapter.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    int visibleItemCount = layoutManager.getChildCount();
    int totalItemCount = layoutManager.getItemCount();
    int pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
    if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
        if (onLoadMoreCommand != null) {
            methodInvoke.onNext(recyclerView.getAdapter().getItemCount());
        }
    }
}
 
Example 18
Source File: ScrollManager.java    From Mover with Apache License 2.0 5 votes vote down vote up
public void loadMoreItemsIfNecessary(RecyclerView recyclerView){
    LinearLayoutManager layout = (LinearLayoutManager) recyclerView.getLayoutManager();

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

    if ((totalItemCount - (firstVisibleItem +
            visibleItemCount)) <= LOAD_IF_LESS_THAN){
        mEventBus.post(mMoreEvent);
    }
}
 
Example 19
Source File: EndlessAdapter.java    From SteamGifts with MIT License 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    if (layoutManager == null)
        throw new IllegalStateException("Can't handle scrolling without a LayoutManager");

    int lastVisibleItem = layoutManager.findLastVisibleItemPosition();

    if (!loading && layoutManager.getItemCount() <= (lastVisibleItem + 5)) {
        startLoading();
    }
}
 
Example 20
Source File: AutoLoadRecyclerView.java    From the-tech-frontier-app with MIT License 4 votes vote down vote up
private boolean isBottom(int dx, int dy) {
    LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
    int lastVisibleItem = layoutManager.findLastVisibleItemPosition();
    int totalItemCount = layoutManager.getItemCount();
    return lastVisibleItem >= totalItemCount - 4 && dy > 0;
}