當前位置: 首頁>>代碼示例>>Java>>正文


Java StaggeredGridLayoutManager.findLastCompletelyVisibleItemPositions方法代碼示例

本文整理匯總了Java中android.support.v7.widget.StaggeredGridLayoutManager.findLastCompletelyVisibleItemPositions方法的典型用法代碼示例。如果您正苦於以下問題:Java StaggeredGridLayoutManager.findLastCompletelyVisibleItemPositions方法的具體用法?Java StaggeredGridLayoutManager.findLastCompletelyVisibleItemPositions怎麽用?Java StaggeredGridLayoutManager.findLastCompletelyVisibleItemPositions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.widget.StaggeredGridLayoutManager的用法示例。


在下文中一共展示了StaggeredGridLayoutManager.findLastCompletelyVisibleItemPositions方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getOnBottomListener

import android.support.v7.widget.StaggeredGridLayoutManager; //導入方法依賴的package包/類
RecyclerView.OnScrollListener getOnBottomListener(StaggeredGridLayoutManager layoutManager) {
    return new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView rv, int dx, int dy) {
            boolean isBottom =
                    layoutManager.findLastCompletelyVisibleItemPositions(new int[2])[1] >=
                            mAdapter.getItemCount() - PRELOAD_SIZE;
            if (!mRefreshLayout.isRefreshing() && isBottom) {
                if (!mIsFirstTimeTouchBottom) {
                    mRefreshLayout.setRefreshing(true);
                    mPage += 1;
                    loadFromNet(false);
                } else {
                    mIsFirstTimeTouchBottom = false;
                }
            }
        }
    };
}
 
開發者ID:weixianshishen,項目名稱:BeautifulGirls,代碼行數:21,代碼來源:MainActivity.java

示例2: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (dy < 0 || loadMoreSubject == null || loadMoreSubject.isLoading()){
        return;
    }

    int lastItem = 0;
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int totalItemCount = layoutManager.getItemCount();
    if (layoutManager instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = ((GridLayoutManager) layoutManager);
        //Position to find the final item of the current LayoutManager
        lastItem = gridLayoutManager.findLastCompletelyVisibleItemPosition();
        if (lastItem == -1){
            lastItem = gridLayoutManager.findLastVisibleItemPosition();
        }
    } else if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = ((LinearLayoutManager) layoutManager);
        lastItem = linearLayoutManager.findLastCompletelyVisibleItemPosition();
        if (lastItem == -1){
            lastItem = linearLayoutManager.findLastVisibleItemPosition();
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = ((StaggeredGridLayoutManager) layoutManager);
        // since may lead to the final item has more than one StaggeredGridLayoutManager the particularity of the so here that is an array
        // this array into an array of position and then take the maximum value that is the last show the position value
        int[] lastPositions = staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(null);
        lastItem = findMax(lastPositions);
    }
    final int childCount = layoutManager.getChildCount();
    final boolean shouldLoadMore = (childCount > 0 && lastItem >= totalItemCount - VISIBLE_THRESHOLD);
    if (shouldLoadMore) {
        loadMoreSubject.onLoadMore();
    }
}
 
開發者ID:yangjiantao,項目名稱:AndroidUiKit,代碼行數:36,代碼來源:LoadMoreDelegate.java

示例3: isLastItem

import android.support.v7.widget.StaggeredGridLayoutManager; //導入方法依賴的package包/類
private boolean isLastItem(RecyclerView.LayoutManager layoutManager) {
    int totalItemCount = layoutManager.getItemCount();
    if (layoutManager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager)
                layoutManager;
        if (null == mPositions) {
            mPositions = new int[staggeredGridLayoutManager.getSpanCount()];
        }
        staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(mPositions);
        return totalItemCount == getLast(mPositions) + 1;
    } else if (layoutManager instanceof LinearLayoutManager){
        return totalItemCount - 1 == ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition();
    }
    return false;
}
 
開發者ID:zuoni1018,項目名稱:CoordinatorLayoutExample-master,代碼行數:16,代碼來源:LoadMoreScrollerListener.java

示例4: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    int lastItem = 0;
    int firstItem = 0;
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int totalItemCount = layoutManager.getItemCount();
    if (layoutManager instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = ((GridLayoutManager) layoutManager);
        firstItem = gridLayoutManager.findFirstCompletelyVisibleItemPosition();
        //Position to find the final item of the current LayoutManager
        lastItem = gridLayoutManager.findLastCompletelyVisibleItemPosition();
        if (lastItem == -1) lastItem = gridLayoutManager.findLastVisibleItemPosition();
    } else if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = ((LinearLayoutManager) layoutManager);
        firstItem = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
        lastItem = linearLayoutManager.findLastCompletelyVisibleItemPosition();
        if (lastItem == -1) lastItem = linearLayoutManager.findLastVisibleItemPosition();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = ((StaggeredGridLayoutManager) layoutManager);
        // since may lead to the final item has more than one StaggeredGridLayoutManager the particularity of the so here that is an array
        // this array into an array of position and then take the maximum value that is the last show the position value
        int[] lastPositions = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
        staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(lastPositions);
        lastItem = findMax(lastPositions);
        firstItem = staggeredGridLayoutManager.findFirstVisibleItemPositions(lastPositions)[0];
    }
    if (firstItem == 0 || firstItem == RecyclerView.NO_POSITION) {
        if (mPullLoadMoreRecyclerView.getPullRefreshEnable())
            mPullLoadMoreRecyclerView.setSwipeRefreshEnable(true);
    } else {
        mPullLoadMoreRecyclerView.setSwipeRefreshEnable(false);
    }
    if (mPullLoadMoreRecyclerView.getPushRefreshEnable()
            && !mPullLoadMoreRecyclerView.isRefresh()
            && mPullLoadMoreRecyclerView.isHasMore()
            && (lastItem == totalItemCount - 1)
            && !mPullLoadMoreRecyclerView.isLoadMore()
            && (dx > 0 || dy > 0)) {
        mPullLoadMoreRecyclerView.setIsLoadMore(true);
        mPullLoadMoreRecyclerView.loadMore();
    }

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:45,代碼來源:RecyclerViewOnScroll.java


注:本文中的android.support.v7.widget.StaggeredGridLayoutManager.findLastCompletelyVisibleItemPositions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。