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


Java LinearLayoutManager.findLastVisibleItemPosition方法代碼示例

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


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

示例1: onScrollStateChanged

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    if (newState != RecyclerView.SCROLL_STATE_IDLE
            || !(recyclerView.getLayoutManager() instanceof LinearLayoutManager)
            || recyclerView.getChildCount() < AVAILABLE) {
        return;
    }

    final LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();

    final int totalItemCount = recyclerView.getAdapter().getItemCount();
    final int lastVisibleItemPosition = manager.findLastVisibleItemPosition();

    if (lastVisibleItemPosition == totalItemCount - 1) {
        mTrack.logEvent(TrackCons.Main.SCROLL_BOTTOM);
    }
}
 
開發者ID:huazhouwang,項目名稱:Synapse,代碼行數:18,代碼來源:MainActivity.java

示例2: onScrolled

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    // 鎖定觸發
    if (loading) {
        return;
    }
    LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    int lastVisiblePosition = layoutManager.findLastVisibleItemPosition();
    int itemCount = layoutManager.getItemCount();

    // 最後一個item剛出現且還能上滑的時候觸發並鎖定防止多次觸發,提前觸發以便無縫銜接,需要用戶加載完數據後手動解鎖
    if (recyclerView.canScrollVertically(1) && (lastVisiblePosition == itemCount - 1)) {
        Log.d("Debug", "OnLoadMore...");
        if (mLoadMoreListener != null) {
            mLoadMoreListener.onLoadMore();
            loading = true;
            notifyDataSetChanged();
        }
    }
}
 
開發者ID:1014277960,項目名稱:DailyReader,代碼行數:22,代碼來源:FooterRVAdapter.java

示例3: renewScrollPosition

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
/**
 * This method calculates the current scroll position and its offset to help new attached
 * recyclerView on window at that position and offset
 *
 * @see #getScrollPosition()
 * @see #getScrollPositionOffset()
 */
private void renewScrollPosition(RecyclerView p_jRecyclerView) {
    LinearLayoutManager layoutManager = (LinearLayoutManager) p_jRecyclerView
            .getLayoutManager();
    m_nScrollPosition = layoutManager.findFirstCompletelyVisibleItemPosition();

    // That means there is no completely visible Position.
    if (m_nScrollPosition == -1) {
        m_nScrollPosition = layoutManager.findFirstVisibleItemPosition();

        // That means there is just a visible item on the screen
        if (layoutManager.findFirstVisibleItemPosition() == layoutManager
                .findLastVisibleItemPosition()) {
            // in this case we use the position which is the last & first visible item.
        } else {
            // That means there are 2 visible item on the screen. However, second one is not
            // completely visible.
            m_nScrollPosition = m_nScrollPosition + 1;
        }
    }

    m_nScrollPositionOffset = p_jRecyclerView.getLayoutManager().findViewByPosition
            (m_nScrollPosition).getLeft();
}
 
開發者ID:evrencoskun,項目名稱:TableView,代碼行數:31,代碼來源:HorizontalRecyclerViewListener.java

示例4: getLastVisibleItemPosition

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
private static int getLastVisibleItemPosition() {
    Class recyclerViewLMClass = recyclerView.getLayoutManager().getClass();
    if (recyclerViewLMClass == LinearLayoutManager.class) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        return linearLayoutManager.findLastVisibleItemPosition();
    } else if (recyclerViewLMClass == GridLayoutManager.class) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
        return gridLayoutManager.findLastVisibleItemPosition();
    } else if (recyclerViewLMClass == StaggeredGridLayoutManager.class || StaggeredGridLayoutManager.class.isAssignableFrom(recyclerViewLMClass)) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) recyclerView.getLayoutManager();
        int[] into = staggeredGridLayoutManager.findLastVisibleItemPositions(null);
        List<Integer> intoList = new ArrayList<>();
        for (int i : into) {
            intoList.add(i);
        }
        return Collections.max(intoList);
    }
    throw new RuntimeException("Unknown LayoutManager class: " + recyclerViewLMClass.toString());
}
 
開發者ID:ZherebtsovAlexandr,項目名稱:MoxySandbox,代碼行數:20,代碼來源:ScrollObservable.java

示例5: onScrollStateChanged

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
@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();
    }
}
 
開發者ID:piscessu,項目名稱:BaseQuickAdapter,代碼行數:13,代碼來源:EndlessScrollListener.java

示例6: getVisibleItemCount

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
public int getVisibleItemCount(){
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    //only LinearLayoutManager can find last visible
    if(layoutManager instanceof LinearLayoutManager){
        LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
        int firstPosition = linearManager.findFirstVisibleItemPosition();
        int lastPosition = linearManager.findLastVisibleItemPosition();
        return lastPosition - firstPosition + 1;
    }else {
        throw new UnsupportedOperationException("only for Linear RecyclerView ");
    }
}
 
開發者ID:ThirtyDegreesRay,項目名稱:OpenHub,代碼行數:13,代碼來源:ListFragment.java

示例7: onScrolled

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的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

示例8: onScrolled

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();

    totalItemCount = linearLayoutManager.getItemCount();
    lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
    if (!loading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
        // End has been reached
        // Do something
        loading = true;
        if (onLoadMoreListener != null) {
            onLoadMoreListener.onLoadMore();
        }
    }
    // 여기까지 무한 스크롤

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

    if((controlsVisible && dy>0) || (!controlsVisible && dy<0)) {
        scrolledDistance += dy;
    }
    // 여기까지 툴바 숨기기
}
 
開發者ID:pooi,項目名稱:Nearby,代碼行數:34,代碼來源:RecordPatientMedicineListCustomAdapter.java

示例9: isAtScrollEnd

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
/**
 * Determine if the scroll event at the end of the recycler view.
 *
 * @return true if at end of linear list recycler view, false otherwise.
 */
static boolean isAtScrollEnd(RecyclerViewScrollEvent recyclerViewScrollEvent) {
    RecyclerView.LayoutManager layoutManager = recyclerViewScrollEvent.view().getLayoutManager();
    if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        return linearLayoutManager.getItemCount() <= (linearLayoutManager.findLastVisibleItemPosition() + 2);
    }
    return false;
}
 
開發者ID:Zeyad-37,項目名稱:RxRedux,代碼行數:14,代碼來源:ScrollEventCalculator.java

示例10: onScrolled

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    if(!loadMoreEnable || !canLoadMore || isLoading ||
            !NetHelper.INSTANCE.getNetEnabled()) return;
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    //only LinearLayoutManager can find last visible
    if(layoutManager instanceof LinearLayoutManager){
        LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
        int lastPosition = linearManager.findLastVisibleItemPosition();
        if(lastPosition == adapter.getItemCount() - 1){
            onLoadMore(curPage + 1);
        }
    }
}
 
開發者ID:ThirtyDegreesRay,項目名稱:OpenHub,代碼行數:16,代碼來源:ListFragment.java

示例11: onScrolled

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的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

示例12: calculateSnapViewPosition

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
/**
 * Finds the position of the View which is closest to the RecyclerView's anchor, either the
 * RecyclerView's start, center or end
 *
 * @return The position of the View closest the to RecyclerView's anchor
 */
private int calculateSnapViewPosition() {
    LinearLayoutManager linearLayoutManager = (LinearLayoutManager) getLayoutManager();

    int parentAnchor = getParentAnchor(orientation, anchor);

    int lastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
    int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();

    View currentViewClosestToAnchor = linearLayoutManager.findViewByPosition(firstVisibleItemPosition);

    int currentViewClosestToAnchorDistance = parentAnchor - getViewAnchor(currentViewClosestToAnchor, orientation, anchor);

    int currentViewClosestToAnchorPosition = firstVisibleItemPosition;

    for(int i = firstVisibleItemPosition + 1; i <= lastVisibleItemPosition; i++) {
        View view = linearLayoutManager.findViewByPosition(i);

        int distanceToCenter = parentAnchor - getViewAnchor(view, orientation, anchor);

        if (Math.abs(distanceToCenter) < Math.abs(currentViewClosestToAnchorDistance)) {
            currentViewClosestToAnchorPosition = i;
            currentViewClosestToAnchorDistance = distanceToCenter;
        }
    }

    return currentViewClosestToAnchorPosition;
}
 
開發者ID:Dan-TD,項目名稱:SnappyRecyclerView,代碼行數:34,代碼來源:SnappingRecyclerView.java


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