View view = rv.getLayoutManager().getChildAt(n);
View view = rv.getLayoutManager().getChildAt(n);
/** @return the first View whose start is before the start of this recycler view */ @Nullable private static View findFirstViewBeforeStart(LayoutManager layoutManager, OrientationHelper helper) { int childCount = layoutManager.getChildCount(); if (childCount == 0) { return null; } View closestChild = null; final int start = helper.getStartAfterPadding(); int absClosest = Integer.MAX_VALUE; for (int i = 0; i < childCount; i++) { final View child = layoutManager.getChildAt(i); int childStart = helper.getDecoratedStart(child); int absDistance = Math.abs(childStart - start); if (childStart < start && absDistance < absClosest) { absClosest = absDistance; closestChild = child; } } return closestChild; }
private int adjustDyForDown(int dy) { final RecyclerView.LayoutManager layoutManager = getLayoutManager(); if (layoutManager == null || !layoutManager.canScrollVertically()) { return 0; } final View firstChild = layoutManager.getChildAt(0); final int position = layoutManager.getPosition(firstChild); if (position == 0) { final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) firstChild.getLayoutParams(); final int maxDy = -(layoutManager.getDecoratedTop(firstChild) - params.topMargin) + layoutManager.getPaddingTop(); if (dy > maxDy) { return maxDy; } } return dy; }
private boolean checkLastItemCompletelyVisible(RecyclerView.LayoutManager mLayoutmanager) { int lastVisiblePosition = mLayoutmanager.getChildCount() - 1; int currentLastVisiblePosition = ((RecyclerView.LayoutParams) mLayoutmanager .getChildAt(lastVisiblePosition).getLayoutParams()).getViewAdapterPosition(); if (currentLastVisiblePosition == mLayoutmanager.getItemCount() - 1) { final View lastVisibleChild = mWrapperView.getChildAt(lastVisiblePosition); if (lastVisibleChild != null) { if (mHeaderContainer != null && mHeaderContainerHeight <= 0) { mHeaderContainerHeight = mHeaderContainer.getMeasuredHeight(); } return lastVisibleChild.getBottom() <= mWrapperView.getBottom(); } } return false; }
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); View lastChildView = recyclerView.getLayoutManager().getChildAt(recyclerView.getLayoutManager().getChildCount() - 1); int lastChildBottom = lastChildView.getBottom(); int recyclerBottom = recyclerView.getBottom() - recyclerView.getPaddingBottom(); int lastPosition = recyclerView.getLayoutManager().getPosition(lastChildView); if (lastChildBottom == recyclerBottom && lastPosition == recyclerView.getLayoutManager().getItemCount() - 1) { if (canLoadMore) { loadPictures(id, false); } } } });
public View getChildAt(int index) { return layoutManager.getChildAt(index); }
@Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (TYPE.equals(Constants.StoryType.STORY_THEME)) return; View lastchildView = recyclerView.getLayoutManager().getChildAt(recyclerView.getLayoutManager().getChildCount() - 1); int lastChildBottomY = lastchildView.getBottom(); int recyclerBottomY = recyclerView.getBottom() - recyclerView.getPaddingBottom(); int lastPosition = recyclerView.getLayoutManager().getPosition(lastchildView); if (lastChildBottomY == recyclerBottomY && newState == RecyclerView.SCROLL_STATE_IDLE && lastPosition == recyclerView.getLayoutManager().getItemCount() - 1) { mPresenter.getBeforeDaily(mdate); } } });
@Override public void onSelectionStateChange(List<BookmarkId> selectedBookmarks) { if (!mDelegate.isSelectionEnabled()) { for (int i = 0; i < getLayoutManager().getChildCount(); ++i) { View child = getLayoutManager().getChildAt(i); if (child instanceof Checkable) ((Checkable) child).setChecked(false); } } }
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); View lastChildView = recyclerView.getLayoutManager().getChildAt(recyclerView.getLayoutManager().getChildCount() - 1); int lastChildBottom = lastChildView.getBottom(); int recyclerBottom = recyclerView.getBottom() - recyclerView.getPaddingBottom(); int lastPosition = recyclerView.getLayoutManager().getPosition(lastChildView); if (lastChildBottom == recyclerBottom && lastPosition == recyclerView.getLayoutManager().getItemCount() - 1) { loadVideo(false); } } });
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (mHeaderView != null) { translateHeader(mRecyclerView.getLayoutManager().getChildAt(0) == mHeaderView ? mRecyclerView.computeVerticalScrollOffset() : mHeaderView.getHeight()); } } });
private boolean checkFirstItemCompletelyVisible(RecyclerView.LayoutManager mLayoutManager) { int firstVisiblePosition = ((RecyclerView.LayoutParams) mLayoutManager.getChildAt(0) .getLayoutParams()).getViewAdapterPosition(); if (firstVisiblePosition == 0) { final View firstVisibleChild = mWrapperView.getChildAt(0); if (firstVisibleChild != null) { return firstVisibleChild.getTop() >= mWrapperView.getTop(); } } return false; }
return; int firstVisiblePosition = ((RecyclerView.LayoutParams) layoutManager.getChildAt(0).getLayoutParams()).getViewAdapterPosition(); int headerPosition = findPinnedHeaderPosition(parent, firstVisiblePosition);
@Override public void onDestroyView() { super.onDestroyView(); // 存储 PageIndex mConfig.saveTopicListPageIndex(pageIndex); // 存储 RecyclerView 滚动位置 View view = mRecyclerView.getLayoutManager().getChildAt(0); int lastPosition = mRecyclerView.getLayoutManager().getPosition(view); mConfig.saveTopicListState(lastPosition, 0); } }
@Override public void onDestroyView() { super.onDestroyView(); // 存储 PageIndex mConfig.saveNewsListPageIndex(pageIndex); // 存储 RecyclerView 滚动位置 View view = mRecyclerView.getLayoutManager().getChildAt(0); int lastPosition = mRecyclerView.getLayoutManager().getPosition(view); mConfig.saveNewsListPosition(lastPosition); } }
@Override public int findTargetSnapPosition(RecyclerView.LayoutManager lm, int velocityX, int velocityY) { final int itemCount = lm.getItemCount(); if (itemCount == 0) { return RecyclerView.NO_POSITION; } final int childCount = lm.getChildCount(); if (childCount == 0) { return RecyclerView.NO_POSITION; } final boolean leftDirection = velocityX > 0; if (leftDirection) { final View leftChild = lm.getChildAt(0); final int leftChildPos = lm.getPosition(leftChild); final int leftChildRight = lm.getDecoratedRight(leftChild); return Math.min(itemCount - 1, leftChildPos + (leftChildRight > 0 ? 1 : 2)); } else { final View rightChild = lm.getChildAt(childCount - 1); final int rightChildPos = lm.getPosition(rightChild); return Math.max(0, rightChildPos - 1); } }
if (layoutManager.getChildAt(i) != null && layoutManager.getChildAt(i).findViewById(playId) != null) { GSYBaseVideoPlayer player = (GSYBaseVideoPlayer) layoutManager.getChildAt(i).findViewById(playId); Rect rect = new Rect(); player.getLocalVisibleRect(rect);
/** * Return the child view that is currently closest to the start of this parent. * * @param layoutManager The {@link LayoutManager} associated with the attached {@link * RecyclerView}. * @param helper The relevant {@link OrientationHelper} for the attached {@link RecyclerView}. * @return the child view that is currently closest to the start of this parent. */ @Nullable private static View findViewClosestToStart( LayoutManager layoutManager, OrientationHelper helper) { int childCount = layoutManager.getChildCount(); if (childCount == 0) { return null; } View closestChild = null; final int start = helper.getStartAfterPadding(); int absClosest = Integer.MAX_VALUE; for (int i = 0; i < childCount; i++) { final View child = layoutManager.getChildAt(i); int childStart = helper.getDecoratedStart(child); int absDistance = Math.abs(childStart - start); /** if child start is closer than previous closest, set it as closest * */ if (absDistance < absClosest) { absClosest = absDistance; closestChild = child; } } return closestChild; }
public static int getTopDecorationHeight(RecyclerView.LayoutManager layoutManager, int position) { final View itemView = layoutManager.getChildAt(position); return (itemView != null) ? layoutManager.getTopDecorationHeight(itemView) : 0; }
public static int getBottomDecorationHeight( RecyclerView.LayoutManager layoutManager, int position) { final View itemView = layoutManager.getChildAt(position); return (itemView != null) ? layoutManager.getBottomDecorationHeight(itemView) : 0; }