当前位置: 首页>>代码示例>>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;未经允许,请勿转载。