本文整理了Java中android.support.v7.widget.GridLayoutManager.findFirstVisibleItemPosition()
方法的一些代码示例,展示了GridLayoutManager.findFirstVisibleItemPosition()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridLayoutManager.findFirstVisibleItemPosition()
方法的具体详情如下:
包路径:android.support.v7.widget.GridLayoutManager
类名称:GridLayoutManager
方法名:findFirstVisibleItemPosition
暂无
代码示例来源:origin: facebook/litho
@Override
public int findFirstVisibleItemPosition() {
return mGridLayoutManager.findFirstVisibleItemPosition();
}
代码示例来源:origin: bumptech/glide
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
if (grid != null) {
int index = layoutManager.findFirstVisibleItemPosition();
outState.putInt(STATE_POSITION_INDEX, index);
}
}
代码示例来源:origin: jdsjlzx/LRecyclerView
/**
* 找出第一个可见的Item的位置
*
* @param layoutManager
* @return
*/
private int findFirstVisiblePosition(RecyclerView.LayoutManager layoutManager) {
int firstVisiblePosition = 0;
if (layoutManager instanceof GridLayoutManager) {
firstVisiblePosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
} else if (layoutManager instanceof LinearLayoutManager) {
firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(into);
firstVisiblePosition = Integer.MAX_VALUE;
for (int pos : into) {
firstVisiblePosition = Math.min(pos, firstVisiblePosition);
}
}
return firstVisiblePosition;
}
代码示例来源:origin: Hitomis/transferee
private void fillByRecyclerView(final List<ImageView> originImageList) {
RecyclerView recyclerView = transConfig.getRecyclerView();
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
ImageView originImage = ((ImageView) recyclerView.getChildAt(i)
.findViewById(transConfig.getImageId()));
originImageList.add(originImage);
}
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
int firstPos = 0, lastPos = 0;
int totalCount = layoutManager.getItemCount();
if (layoutManager instanceof GridLayoutManager) {
GridLayoutManager gridLayMan = (GridLayoutManager) layoutManager;
firstPos = gridLayMan.findFirstVisibleItemPosition();
lastPos = gridLayMan.findLastVisibleItemPosition();
} else if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linLayMan = (LinearLayoutManager) layoutManager;
firstPos = linLayMan.findFirstVisibleItemPosition();
lastPos = linLayMan.findLastVisibleItemPosition();
}
fillPlaceHolder(originImageList, totalCount, firstPos, lastPos);
}
代码示例来源:origin: zhihu/Matisse
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);
}
}
}
}
代码示例来源:origin: iMeiji/Toutiao
int firstVisiblePostion = gridLayoutManager.findFirstVisibleItemPosition();
if (firstVisiblePostion == 0) {
代码示例来源:origin: jdsjlzx/LRecyclerView
break;
case GridLayout:
firstVisibleItemPosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
代码示例来源:origin: jdsjlzx/LRecyclerView
break;
case GridLayout:
firstVisibleItemPosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
代码示例来源:origin: blipinsk/RecyclerViewHeader
public final boolean isFirstRowVisible() {
if (linear != null) {
return linear.findFirstVisibleItemPosition() == 0;
} else if (grid != null) {
return grid.findFirstVisibleItemPosition() == 0;
// } else if (staggeredGrid != null) {
// return staggeredGrid.findFirstCompletelyVisibleItemPositions() //TODO: 05.04.2016 implement staggered
}
return false; //shouldn't get here
}
代码示例来源:origin: oubowu/PinnedSectionItemDecoration
/**
* 找出第一个可见的Item的位置
*
* @param layoutManager
* @return
*/
private int findFirstVisiblePosition(RecyclerView.LayoutManager layoutManager) {
int firstVisiblePosition = 0;
if (layoutManager instanceof GridLayoutManager) {
firstVisiblePosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
} else if (layoutManager instanceof LinearLayoutManager) {
firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(into);
firstVisiblePosition = Integer.MAX_VALUE;
for (int pos : into) {
firstVisiblePosition = Math.min(pos, firstVisiblePosition);
}
}
return firstVisiblePosition;
}
代码示例来源:origin: oubowu/PinnedSectionItemDecoration
mFirstVisiblePosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
} else if (layoutManager instanceof LinearLayoutManager) {
mFirstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
代码示例来源:origin: HomHomLin/Android-PullToRefreshRecyclerView
public int findFirstVisibleItemPosition(RecyclerView.LayoutManager layoutManager){
if(layoutManager != null) {
if (layoutManager instanceof LinearLayoutManager) {
return ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
}
if (layoutManager instanceof GridLayoutManager) {
return ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
}
}
return RecyclerView.NO_POSITION;
}
}
代码示例来源:origin: mengzhidaren/RecyclerViewVideoDemo
public final boolean isFirstRowVisible() {
if (linear != null) {
return linear.findFirstVisibleItemPosition() == 0;
} else if (grid != null) {
return grid.findFirstVisibleItemPosition() == 0;
// } else if (staggeredGrid != null) {
// return staggeredGrid.findFirstCompletelyVisibleItemPositions() //TODO: 05.04.2016 implement staggered
}
return false; //shouldn't get here
}
代码示例来源:origin: mengzhidaren/RecylerViewMultiHeaderView
public final boolean isFirstRowVisible() {
if (linear != null) {
return linear.findFirstVisibleItemPosition() == 0;
} else if (grid != null) {
return grid.findFirstVisibleItemPosition() == 0;
// } else if (staggeredGrid != null) {
// return staggeredGrid.findFirstCompletelyVisibleItemPositions() //TODO: 05.04.2016 implement staggered
}
return false; //shouldn't get here
}
代码示例来源:origin: open-android/BaseRecyclerAndAdapter
public final boolean isFirstRowVisible() {
if (linear != null) {
return linear.findFirstVisibleItemPosition() == 0;
} else if (grid != null) {
return grid.findFirstVisibleItemPosition() == 0;
// } else if (staggeredGrid != null) {
// return staggeredGrid.findFirstCompletelyVisibleItemPositions() //TODO: 05.04.2016 implement staggered
}
return false; //shouldn't get here
}
代码示例来源:origin: open-android/BaseRecyclerAndAdapter
public final boolean isFirstRowVisible() {
if (linear != null) {
return linear.findFirstVisibleItemPosition() == 0;
} else if (grid != null) {
return grid.findFirstVisibleItemPosition() == 0;
// } else if (staggeredGrid != null) {
// return staggeredGrid.findFirstCompletelyVisibleItemPositions() //TODO: 05.04.2016 implement staggered
}
return false; //shouldn't get here
}
代码示例来源:origin: sdwfqin/AndroidSamples
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (move && newState == RecyclerView.SCROLL_STATE_IDLE) {
move = false;
int n = mIndex - mManager.findFirstVisibleItemPosition();
if (0 <= n && n < mRv.getChildCount()) {
int top = mRv.getChildAt(n).getTop();
mRv.smoothScrollBy(0, top);
}
}
}
代码示例来源:origin: wustor/GangedRecyclerview
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (move) {
move = false;
int n = mIndex - mManager.findFirstVisibleItemPosition();
if (0 <= n && n < mRv.getChildCount()) {
int top = mRv.getChildAt(n).getTop();
mRv.scrollBy(0, top);
}
}
}
}
代码示例来源:origin: qyxxjd/CommonAdapter
private int findFirstVisibleItemPosition(RecyclerView.LayoutManager layoutManager) {
if (layoutManager instanceof GridLayoutManager) {
return ((GridLayoutManager)layoutManager).findFirstVisibleItemPosition();
} else if (layoutManager instanceof LinearLayoutManager) {
return ((LinearLayoutManager)layoutManager).findFirstVisibleItemPosition();
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
return ((StaggeredGridLayoutManager)layoutManager).findFirstVisibleItemPositions(null)[0];
} else {
return getFirstVisibleItemPositions();
}
}
}
代码示例来源:origin: sdwfqin/AndroidSamples
private void smoothMoveToPosition(int n) {
int firstItem = mManager.findFirstVisibleItemPosition();
int lastItem = mManager.findLastVisibleItemPosition();
if (n <= firstItem) {
mRv.scrollToPosition(n);
} else if (n <= lastItem) {
int top = mRv.getChildAt(n - firstItem).getTop();
mRv.scrollBy(0, top);
} else {
mRv.scrollToPosition(n);
move = true;
}
}
内容来源于网络,如有侵权,请联系作者删除!