本文整理汇总了Java中android.support.v7.widget.GridLayoutManager.findLastVisibleItemPosition方法的典型用法代码示例。如果您正苦于以下问题:Java GridLayoutManager.findLastVisibleItemPosition方法的具体用法?Java GridLayoutManager.findLastVisibleItemPosition怎么用?Java GridLayoutManager.findLastVisibleItemPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.GridLayoutManager
的用法示例。
在下文中一共展示了GridLayoutManager.findLastVisibleItemPosition方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getLastVisibleItemPosition
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的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());
}
示例3: 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);
}
}
}
}
示例4: onScrollStateChanged
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrollStateChanged(int state) {
super.onScrollStateChanged(state);
switch (state) {
case SCROLL_STATE_IDLE:
LayoutManager layoutManager = getLayoutManager();
int itemCount = getAdapter().getItemCount();
int lastVisibleItemPosition = 0;
if (layoutManager instanceof GridLayoutManager) {
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
lastVisibleItemPosition = gridLayoutManager.findLastVisibleItemPosition();
} else if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
lastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
}
if (lastVisibleItemPosition >= itemCount - 1) {
if (getParent() instanceof SwipeRefreshLayout) {
SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getParent();
if (swipeRefreshLayout.isRefreshing()) {
break;
}
}
if (mOnLoadMoreListener != null && mScrollDy > 0) {
if (!mIsLoadingMore) {
synchronized (EnhanceRecyclerView.class) {
if (!mIsLoadingMore) {
mIsLoadingMore = true;
mInternalAdapter.setFootViewVisible(true);
mOnLoadMoreListener.onLoadMore();
}
}
}
}
}
break;
}
}
示例5: onScrolled
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的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();
}
}
示例6: 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);
}
示例7: 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;
}
}
示例8: checkForNewElements
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public void checkForNewElements(RecyclerView recyclerView) {
int currentOffset = mLazyFetchingActivity.getCurrentOffset();
int maxElementsToFetchTotal = mLazyFetchingActivity.getMaxElementsToFetch();
// If the task has already been run, make a new task as a task can only be run once.
if(getElementsTask.getStatus() == AsyncTask.Status.FINISHED) {
getElementsTask = new GetVisualElementsTask<>();
}
// Only bother to check if we need to fetch more game objects if we are not already in the process of doing so.
if(getElementsTask.getStatus() != AsyncTask.Status.RUNNING && currentOffset < maxElementsToFetchTotal) {
GridLayoutManager lm = (GridLayoutManager) recyclerView.getLayoutManager();
RecyclerView.Adapter mAdapter = recyclerView.getAdapter();
if (mAdapter == null ){
return;
}
int lastViewPosition = lm.findLastVisibleItemPosition();
int spanCount = lm.getSpanCount();
int itemCount = mAdapter.getItemCount();
final double FETCH_WHEN_BELOW_FIVE = 5;
final double NUMBER_OF_ROWS = Math.ceil(itemCount / (spanCount * 1.0)); // Round UP to the nearest Integer
final double LAST_ROW_VISIBLE = Math.ceil(lastViewPosition/(spanCount * 1.0)); // Round UP to the nearest Integer
// If the Second to last or the last row is visible, then fetch more game objects.
if(LAST_ROW_VISIBLE >= NUMBER_OF_ROWS - FETCH_WHEN_BELOW_FIVE) {
getElementsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mLazyFetchingActivity);
mLazyFetchingActivity.startProgress();
}
}
}
示例9: 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;
}
}
示例10: 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();
}
}
示例11: onScrolled
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if(listener == null){
return;
}
IOnLoadMoreListener iOnLoadMoreListener = listener.get();
if(iOnLoadMoreListener!=null) {
iOnLoadMoreListener.onBeforeScroll(dx, dy);
if (layoutManager instanceof LinearLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
mLastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
int firstVisible = linearLayoutManager.findFirstVisibleItemPosition();
iOnLoadMoreListener.notifyAppearStateChange(firstVisible
, mLastVisibleItemPosition
, dx
, dy);
} else if (layoutManager instanceof GridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
mLastVisibleItemPosition = gridLayoutManager.findLastVisibleItemPosition();
iOnLoadMoreListener.notifyAppearStateChange(gridLayoutManager.findFirstVisibleItemPosition()
, mLastVisibleItemPosition
, dx
, dy);
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
int newSpanCount = staggeredGridLayoutManager.getSpanCount();
if (mLastPositions == null || newSpanCount != mLastPositions.length) {
mLastPositions = new int[newSpanCount];
}
if (mFirstPositions == null || newSpanCount != mFirstPositions.length) {
mFirstPositions = new int[newSpanCount];
}
//avoid crash of support-v7 original bug
try{
staggeredGridLayoutManager.findFirstVisibleItemPositions(mFirstPositions);
mFirstVisibleItemPosition = findMin(mFirstPositions);
staggeredGridLayoutManager.findLastVisibleItemPositions(mLastPositions);
mLastVisibleItemPosition = findMax(mLastPositions);
iOnLoadMoreListener.notifyAppearStateChange(
mFirstVisibleItemPosition
, mLastVisibleItemPosition
, dx
, dy);
}catch(Exception e){
e.printStackTrace();
WXLogUtils.e(e.toString());
}
} else {
throw new RuntimeException(
"Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
}
}
}