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


Java GridLayoutManager.findFirstVisibleItemPosition方法代码示例

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


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

示例1: refreshSelection

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public void refreshSelection() {
    GridLayoutManager layoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
    int first = layoutManager.findFirstVisibleItemPosition();
    int last = layoutManager.findLastVisibleItemPosition();
    if (first == -1 || last == -1) {
        return;
    }
    Cursor cursor = getCursor();
    for (int i = first; i <= last; i++) {
        RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(first);
        if (holder instanceof MediaViewHolder) {
            if (cursor.moveToPosition(i)) {
                setCheckStatus(Item.valueOf(cursor), ((MediaViewHolder) holder).mMediaGrid);
            }
        }
    }
}
 
开发者ID:sathishmscict,项目名称:Matisse-Image-and-Video-Selector,代码行数:18,代码来源:AlbumMediaAdapter.java

示例2: refreshSelection

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public void refreshSelection() {
    GridLayoutManager layoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
    int first = layoutManager.findFirstVisibleItemPosition();
    int last = layoutManager.findLastVisibleItemPosition();
    if (first == -1 || last == -1) {
        return;
    }
    Cursor cursor = getCursor();
    for (int i = first; i <= last; i++) {
        RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(first);
        if (holder instanceof MediaViewHolder) {
            if (cursor.moveToPosition(i)) {
                setCheckStatus(MediaInfo.valueOf(cursor), ((MediaViewHolder) holder).mMediaGrid);
            }
        }
    }
}
 
开发者ID:GitPhoenix,项目名称:VanGogh,代码行数:18,代码来源:VanMediaAdapter.java

示例3: onScrollStateChanged

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    onPageScrollStateChanged(newState);

    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

        int position = 0;
        if (layoutManager instanceof GridLayoutManager) {
            GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
            position = gridLayoutManager.findFirstVisibleItemPosition();
            int row = gridLayoutManager.getSpanCount();
            position = position / (row * mPageColumn);
        } else if (layoutManager instanceof LinearLayoutManager) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            position = linearLayoutManager.findFirstVisibleItemPosition();
        }

        onPageSelected(position);
    }
}
 
开发者ID:hanhailong,项目名称:GridPagerSnapHelper,代码行数:24,代码来源:BasePageIndicator.java

示例4: 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

示例5: isScrollTop

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private boolean isScrollTop(MotionEvent ev) {
    LayoutManager layoutManager = getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        if (gridLayoutManager.findFirstVisibleItemPosition() == 0 &&
                gridLayoutManager.findViewByPosition(0).getTop() == gridLayoutManager.getTopDecorationHeight(gridLayoutManager.findViewByPosition(0))) {
            if (!scrollTop) {
                dragDistanceY = (int) (downPositionY - ev.getRawY());
                scrollTop = true;
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:Skykai521,项目名称:InstagramPhotoPicker,代码行数:16,代码来源:CoordinatorRecyclerView.java

示例6: checkIsBackFromMainActivity

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
 * Checks if the user started this activity by pressing the back button on another main activity.
 * If so it runs the show animation for the activity's icon, text and visual elements.
 */
public void checkIsBackFromMainActivity() {
	if(isTransitioned) {
		GridLayoutManager manager = (GridLayoutManager) mRecyclerView.getLayoutManager();
		final int DELAY_BETWEEN = 50;
		int firstVisibleItemPosition = manager.findFirstVisibleItemPosition();
		int lastVisibleItemPosition = manager.findLastVisibleItemPosition();

		int startPositionCol = AnimationService.getColumnPosFromIndex(firstVisibleItemPosition, mRecyclerView);
		int startPositionRow = AnimationService.getRowPosFromIndex(firstVisibleItemPosition, mRecyclerView);

		// Show the Activity Icon and Text
		AnimationService.startAlphaRevealAnimation(mCircleIconWrapper);
		AnimationService.startAlphaRevealAnimation(mTitleView);

		// Fake fill the RecyclerViews with children again
		for(int i = firstVisibleItemPosition; i <= lastVisibleItemPosition; i++) {
			final View mView = mRecyclerView.getChildAt(i-firstVisibleItemPosition);

			int positionColumnDistance = Math.abs(AnimationService.getColumnPosFromIndex(i, mRecyclerView) - startPositionCol);
			int positionRowDistance = Math.abs(AnimationService.getRowPosFromIndex(i, mRecyclerView) - startPositionRow);
			int delay = (positionColumnDistance + positionRowDistance) * DELAY_BETWEEN;

			//int delay = (i - firstVisibleItemPosition) * DELAY_BETWEEN;
			if(mView != null) {
				AnimationService.startAlphaRevealAnimation(delay, mView, mAdapter instanceof StreamsAdapter);
			}
		}
		isTransitioned = false;
	}
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:35,代码来源:MainActivity.java

示例7: scroll_load_more_detection

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private void scroll_load_more_detection(RecyclerView recyclerView) {

        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

        if (layoutManagerType == null) {
            if (layoutManager instanceof GridLayoutManager) {
                layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
            } else if (layoutManager instanceof StaggeredGridLayoutManager) {
                layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
            } else if (layoutManager instanceof LinearLayoutManager) {
                layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
            } else {
                throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
            }
        }

        mTotalItemCount = layoutManager.getItemCount();
        mVisibleItemCount = layoutManager.getChildCount();

        switch (layoutManagerType) {
            case LINEAR:
                mFirstVisibleItem = mRecyclerViewHelper.findFirstVisibleItemPosition();
                lastVisibleItemPosition = mRecyclerViewHelper.findLastVisibleItemPosition();
                break;
            case GRID:
                if (layoutManager instanceof GridLayoutManager) {
                    GridLayoutManager ly = (GridLayoutManager) layoutManager;
                    lastVisibleItemPosition = ly.findLastVisibleItemPosition();
                    mFirstVisibleItem = ly.findFirstVisibleItemPosition();
                }
                break;
            case STAGGERED_GRID:
                if (layoutManager instanceof StaggeredGridLayoutManager) {
                    StaggeredGridLayoutManager sy = (StaggeredGridLayoutManager) layoutManager;

                    if (mlastPositionsStaggeredGridLayout == null)
                        mlastPositionsStaggeredGridLayout = new int[sy.getSpanCount()];

                    sy.findLastVisibleItemPositions(mlastPositionsStaggeredGridLayout);
                    lastVisibleItemPosition = findMax(mlastPositionsStaggeredGridLayout);

                    sy.findFirstVisibleItemPositions(mlastPositionsStaggeredGridLayout);
                    mFirstVisibleItem = findMin(mlastPositionsStaggeredGridLayout);
                }
                break;
        }

        if (automaticLoadMoreEnabled) {

            if (mTotalItemCount > previousTotal) {
                automaticLoadMoreEnabled = false;
                previousTotal = mTotalItemCount;
            }
        }

        boolean bottomEdgeHit = (mTotalItemCount - mVisibleItemCount) <= mFirstVisibleItem;

        if (bottomEdgeHit) {
            if (mIsLoadMoreWidgetEnabled) {
                /**auto activate load more**/
                if (!automaticLoadMoreEnabled) {
                    onLoadMoreListener.loadMore(mRecyclerView.getAdapter().getItemCount(), lastVisibleItemPosition);
                    automaticLoadMoreEnabled = true;
                }
            }
            mAdapter.internalExecuteLoadingView();
            previousTotal = mTotalItemCount;
        }
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:70,代码来源:UltimateRecyclerView.java

示例8: isAtLastElementOfGridLayoutManager

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private boolean isAtLastElementOfGridLayoutManager(GridLayoutManager gridLayoutManager) {
    visibleItemCount = gridLayoutManager.getChildCount();
    totalItemCount = gridLayoutManager.getItemCount();
    pastVisibleItems = gridLayoutManager.findFirstVisibleItemPosition();
    return (visibleItemCount + pastVisibleItems) >= totalItemCount - VISIBILITY_THRESHOLD;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:7,代码来源:EndlessRecyclerOnScrollListener.java

示例9: drawGrid

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
protected void drawGrid(Canvas c, RecyclerView.LayoutManager manager) {
    final GridLayoutManager layoutManager = (GridLayoutManager) manager;
    final int spanCount = layoutManager.getSpanCount();
    int itemCount = layoutManager.getItemCount();

    final int firstItem = layoutManager.findFirstVisibleItemPosition();
    for (int i = 0; i < layoutManager.getChildCount(); i++) {
        final View view = layoutManager.findViewByPosition(firstItem + i);
        if (view != null) {
            final RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
            final int viewLayoutPosition = layoutParams.getViewLayoutPosition();//布局时当前View的位置

            if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) {
                //垂直方向
                if (isLastOfGrid(itemCount, viewLayoutPosition, spanCount)/*判断是否是最后一排*/) {
                    if (viewLayoutPosition == itemCount - 1 /*最后一个*/) {
                        if (drawLastVLine) {
                            drawDrawableV(c, view);
                        }
                        if (drawLastHLine) {
                            drawDrawableH(c, view);
                        }
                    } else {
                        drawDrawableV(c, view);
                    }
                } else {
                    if (isEndOfGrid(itemCount, viewLayoutPosition, spanCount)/*判断是否是最靠右的一排*/) {
                        drawDrawableH(c, view);

                        if (drawLastVLine) {
                            drawDrawableV(c, view);
                        }
                    } else {
                        drawDrawableH(c, view);
                        drawDrawableV(c, view);
                    }
                }
            } else {
                //水平方向
                if (isLastOfGrid(itemCount, viewLayoutPosition, spanCount)) {
                    if (viewLayoutPosition == itemCount - 1 /*最后一个*/) {
                        if (drawLastVLine) {
                            drawDrawableV(c, view);
                        }
                        if (drawLastHLine) {
                            drawDrawableH(c, view);
                        }
                    } else {
                        drawDrawableH(c, view);
                    }
                } else {
                    if (isEndOfGrid(itemCount, viewLayoutPosition, spanCount)) {
                        drawDrawableV(c, view);

                        if (drawLastHLine) {
                            drawDrawableH(c, view);
                        }
                    } else {
                        drawDrawableH(c, view);
                        drawDrawableV(c, view);
                    }
                }
            }
        }
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:67,代码来源:RBaseItemDecoration.java


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