Java Code Examples for android.support.v7.widget.GridLayoutManager#findLastVisibleItemPosition()
The following examples show how to use
android.support.v7.widget.GridLayoutManager#findLastVisibleItemPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlbumMediaAdapter.java From AlbumCameraRecorder with MIT License | 6 votes |
/** * 刷新所能看到的选择 */ public void refreshSelection() { GridLayoutManager layoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager(); // 获取当前能看到的第一个,和最后一个 int first = layoutManager.findFirstVisibleItemPosition(); int last = layoutManager.findLastVisibleItemPosition(); if (first == -1 || last == -1) { // 如果是-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(MultiMedia.valueOf(cursor), ((MediaViewHolder) holder).mMediaGrid); } } } }
Example 2
Source File: AlbumMediaAdapter.java From Matisse with Apache License 2.0 | 6 votes |
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); } } } }
Example 3
Source File: LoadMoreDelegate.java From AndroidUiKit with Apache License 2.0 | 5 votes |
@Override public void onScrolled(@NonNull 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(); } }
Example 4
Source File: ChannelFragmentAdapter.java From letv with Apache License 2.0 | 5 votes |
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); }
Example 5
Source File: WXRecyclerViewOnScrollListener.java From ucar-weex-core with Apache License 2.0 | 4 votes |
@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"); } } }