本文整理汇总了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);
}
}
}
}
示例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);
}
}
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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);
}
}
}
}
}
}