当前位置: 首页>>代码示例>>Java>>正文


Java GridLayoutManager.findFirstCompletelyVisibleItemPosition方法代码示例

本文整理汇总了Java中android.support.v7.widget.GridLayoutManager.findFirstCompletelyVisibleItemPosition方法的典型用法代码示例。如果您正苦于以下问题:Java GridLayoutManager.findFirstCompletelyVisibleItemPosition方法的具体用法?Java GridLayoutManager.findFirstCompletelyVisibleItemPosition怎么用?Java GridLayoutManager.findFirstCompletelyVisibleItemPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.GridLayoutManager的用法示例。


在下文中一共展示了GridLayoutManager.findFirstCompletelyVisibleItemPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doClickOtherToNavigation

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private void doClickOtherToNavigation(ViewGroup parent, int position, MyViewHolder myHolder) {
    RecyclerView recyclerView = (RecyclerView) parent;
    LayoutManager manager = recyclerView.getLayoutManager();
    View currentView = manager.findViewByPosition(myHolder.getAdapterPosition());
    View preTargetView = manager.findViewByPosition(this.mTopSize);
    GridLayoutManager gridLayoutManager = (GridLayoutManager) manager;
    int spanCount = gridLayoutManager.getSpanCount();
    int targetPosition = this.mTopSize + 1;
    if (recyclerView.indexOfChild(preTargetView) >= 0) {
        int targetX = preTargetView.getLeft();
        int targetY = preTargetView.getTop();
        if ((targetPosition - 1) % spanCount == 0) {
            View targetView = manager.findViewByPosition(targetPosition);
            targetX = targetView.getLeft();
            targetY = targetView.getTop();
        } else {
            targetX += preTargetView.getWidth() + UIsUtils.dipToPx(TitleBar.SHAREBTN_RIGHT_MARGIN);
            if (gridLayoutManager.findLastVisibleItemPosition() == getItemCount() - 1 && (((getItemCount() - 1) - this.mTopSize) - 2) % spanCount == 0) {
                if (gridLayoutManager.findFirstVisibleItemPosition() != 0) {
                    targetY += preTargetView.getHeight() + UIsUtils.dipToPx(TitleBar.SHAREBTN_RIGHT_MARGIN);
                } else if (gridLayoutManager.findFirstCompletelyVisibleItemPosition() != 0) {
                    targetY += (-recyclerView.getChildAt(0).getTop()) - recyclerView.getPaddingTop();
                }
            }
        }
        moveOtherToMy(myHolder);
        startAnimation(recyclerView, currentView, (float) targetX, (float) targetY);
        return;
    }
    moveOtherToMy(myHolder);
    int index = (this.mTopSize % spanCount) - 1;
    if (index < 0) {
        index = spanCount - 1;
    }
    startAnimation(recyclerView, currentView, (float) ((currentView.getWidth() * index) + (index == 0 ? 0 : (index - 1) * UIsUtils.dipToPx(TitleBar.SHAREBTN_RIGHT_MARGIN))), 0.0f);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:37,代码来源:ChannelFragmentAdapter.java

示例2: onScrolled

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的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.GridLayoutManager.findFirstCompletelyVisibleItemPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。