View lastChild = rv.getChildAt(rv.getChildCount() - 1); return (rv.getAdapter().getItemCount() - 1) * lm.getDecoratedMeasuredHeight(lastChild) + lm.getDecoratedBottom(lastChild) - rv.getBottom();
private boolean isScrollToBottom() { RecyclerView recyclerView = pullLoadMoreRecyclerView.getRecyclerView(); int lastVisiblePosition = recyclerView.getChildAdapterPosition( recyclerView.getChildAt(recyclerView.getChildCount() - 1)); if (lastVisiblePosition >= recyclerView.getAdapter().getItemCount() - 1) { return recyclerView.getChildAt(recyclerView.getChildCount() - 1).getBottom() <= recyclerView.getBottom(); } return false; }
public void drawHorizontal(Canvas c, RecyclerView parent) { int childCount = parent.getChildCount(); if (childCount == 0) return; int left, top, right, bottom; View currentChild; for (int i = 0; i < childCount; i++) { currentChild = parent.getChildAt(i); int currentChildBottom = currentChild.getBottom(); if (currentChildBottom > parent.getPaddingTop() && currentChildBottom < parent.getBottom() - parent.getPaddingBottom()) { left = currentChild.getLeft(); right = currentChild.getRight(); top = currentChildBottom; bottom = top + divider.getIntrinsicHeight(); divider.setBounds(left, top, right, bottom); divider.draw(c); } } }
public void drawToTheRightOfEachChildren(Canvas c, RecyclerView parent) { if (parent.getChildCount() == 0) return; int top, left, right, bottom; int childCount = parent.getChildCount(); View currentChild; for (int i = 0; i < childCount; i++) { currentChild = parent.getChildAt(i); int offset = 2; if (currentChild.getRight() < parent.getRight() - parent.getPaddingRight() - offset) { //Avoid drawing over top padding top = currentChild.getTop(); if (top < parent.getPaddingTop()) { top = parent.getPaddingTop(); } bottom = currentChild.getBottom() + divider.getIntrinsicHeight(); //Avoid drawing over bottom padding int parentBottom = parent.getBottom() - parent.getPaddingBottom(); if (bottom > parentBottom) { bottom = parentBottom; } left = currentChild.getRight(); right = left + divider.getIntrinsicWidth(); divider.setBounds(left, top, right, bottom); divider.draw(c); } } }
@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 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 onDraw(Canvas canvas, RecyclerView recyclerview, RecyclerView.State state) { int count = recyclerview.getChildCount(); View child; for (int i = 0; i < count; i++) { child = recyclerview.getChildAt(i); if (recyclerview.getChildViewHolder(child).getAdapterPosition() >= mDividerIndex) { RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); int childTop = child.getTop(); int topMargin = layoutParams.topMargin; int childTranslationY = Math.round(child.getTranslationY()); mDrawable.setBounds(0, childTop + topMargin + childTranslationY, recyclerview.getWidth(), recyclerview.getBottom()); mDrawable.draw(canvas); } } } };
@Override protected boolean isReadyForPullEnd() { int lastVisiblePosition = getRefreshableView().getChildAdapterPosition(getRefreshableView().getChildAt(getRefreshableView().getChildCount() -1)); if (lastVisiblePosition >= getRefreshableView().getAdapter().getItemCount()-1) { return getRefreshableView().getChildAt(getRefreshableView().getChildCount() - 1).getBottom() <= getRefreshableView().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); } } } });
@Override protected void layoutChild(CoordinatorLayout parent, RecyclerView child, int layoutDirection) { super.layoutChild(parent, child, layoutDirection); if (calendarHeight == 0) { final List<View> dependencies = parent.getDependencies(child); for (int i = 0, z = dependencies.size(); i < z; i++) { View view = dependencies.get(i); if (view instanceof MaterialCalendarView) { calendarHeight = view.getMeasuredHeight(); } } } child.setTop(calendarHeight); child.setBottom(child.getBottom() + calendarHeight); } }
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); //得到当前显示的最后一个item的view View lastChildView = recyclerView.getLayoutManager().getChildAt(recyclerView.getLayoutManager().getChildCount()-1); if (lastChildView == null) return; //得到lastChildView的bottom坐标值 int lastChildBottom = lastChildView.getBottom(); //得到Recyclerview的底部坐标减去底部padding值,也就是显示内容最底部的坐标 int recyclerBottom = recyclerView.getBottom()-recyclerView.getPaddingBottom(); //通过这个lastChildView得到这个view当前的position值 int lastVisiblePosition = layoutManager.findLastVisibleItemPosition(); //判断lastChildView的bottom值跟recyclerBottom //判断lastPosition是不是最后一个position //如果两个条件都满足则说明是真正的滑动到了底部 int lastPosition = recyclerView.getLayoutManager().getItemCount() - 1; if(lastChildBottom == recyclerBottom && lastVisiblePosition == lastPosition){ bottom = true; viewModel.canRefresh.set(true); }else{ bottom = false; } if (lastVisiblePosition >= lastPosition - 3) viewModel.tryToLoadFromBottom(); } });
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); //得到当前显示的最后一个item的view View lastChildView = recyclerView.getLayoutManager().getChildAt(recyclerView.getLayoutManager().getChildCount()-1); //得到lastChildView的bottom坐标值 int lastChildBottom = lastChildView.getBottom(); //得到Recyclerview的底部坐标减去底部padding值,也就是显示内容最底部的坐标 int recyclerBottom = recyclerView.getBottom()-recyclerView.getPaddingBottom(); //通过这个lastChildView得到这个view当前的position值 int lastVisiblePosition = recyclerView.getLayoutManager().getPosition(lastChildView); //判断lastChildView的bottom值跟recyclerBottom //判断lastPosition是不是最后一个position //如果两个条件都满足则说明是真正的滑动到了底部 /* Why <= ? */ int lastPosition = recyclerView.getLayoutManager().getItemCount() - 1; if(lastChildBottom == recyclerBottom && lastPosition == recyclerView.getLayoutManager().getItemCount()-1 ){ bottom = true; mSwipyRefreshLayout.setEnabled(true); }else{ bottom = false; } if (lastVisiblePosition >= lastPosition - 3) viewModel.tryToLoadMore(); } });
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); //得到当前显示的最后一个item的view View lastChildView = recyclerView.getLayoutManager().getChildAt(recyclerView.getLayoutManager().getChildCount()-1); if (lastChildView == null) return; //得到lastChildView的bottom坐标值 int lastChildBottom = lastChildView.getBottom(); //得到Recyclerview的底部坐标减去底部padding值,也就是显示内容最底部的坐标 int recyclerBottom = recyclerView.getBottom()-recyclerView.getPaddingBottom(); //通过这个lastChildView得到这个view当前的position值 int lastVisiblePosition = recyclerView.getLayoutManager().getPosition(lastChildView); //判断lastChildView的bottom值跟recyclerBottom //判断lastPosition是不是最后一个position //如果两个条件都满足则说明是真正的滑动到了底部 /* Why <= ? */ int lastPosition = recyclerView.getLayoutManager().getItemCount() - 1; if(lastChildBottom <= recyclerBottom && lastVisiblePosition == lastPosition){ bottom = true; if (appBarLayout.getState() == MyAppBarLayout.State.COLLAPSED) { viewModel.canRefresh.set(true); Log.d(TAG, "onScrolled: collapsed"); } }else{ bottom = false; } if (lastVisiblePosition >= lastPosition - 3) viewModel.tryToLoadFromBottom(); } });
View lastChild = rv.getChildAt(rv.getChildCount() - 1); return (rv.getAdapter().getItemCount() - 1) * lm.getDecoratedMeasuredHeight(lastChild) + lm.getDecoratedBottom(lastChild) - rv.getBottom();
private void dragProgress(int y) { overlay.setTranslationY(y - adjustY); if(y<SCROLL_THRESHOLD) { //int first = layoutManager.findFirstVisibleItemPosition(); //if(first>0) recyclerView.scrollToPosition(first-1); recyclerView.scrollBy(0, -SCROLL_AMOUNT); } else if(y>recyclerView.getBottom()-SCROLL_THRESHOLD) { //recyclerView.scrollToPosition(layoutManager.findLastVisibleItemPosition()+1); recyclerView.scrollBy(0, SCROLL_AMOUNT); } View viewUnder = recyclerView.findChildViewUnder(10, y); if(viewUnder!=null && !viewUnder.equals(draggingView)) { int newPosition = recyclerView.getChildPosition(viewUnder); if(viewUnder.getId()==layoutHeaderId) return; adapter.swapItems(currentPosition, newPosition); currentPosition = newPosition; } }
@Override public final void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { centerItemPosition = IDLE_POSITION; if (!(parent.getLayoutManager() instanceof LinearLayoutManager)) return; LinearLayoutManager llm = (LinearLayoutManager) parent.getLayoutManager(); boolean isVertical = llm.getOrientation() == LinearLayoutManager.VERTICAL;//垂直与水平布局方式 Rect parentRect = new Rect(parent.getLeft(), parent.getTop(), parent.getRight(), parent.getBottom()); int startPosition = llm.findFirstVisibleItemPosition(); if (startPosition < 0) return; int endPosition = llm.findLastVisibleItemPosition(); hasCenterItem = false; for (int itemPosition = startPosition; itemPosition <= endPosition; itemPosition++) { if (itemPosition < itemCount) continue;//itemCount为空白项,不考虑 if (itemPosition >= llm.getItemCount() - itemCount) break;//超过列表的也是空白项 //Log.i("you", "onDraw currentItem... " + itemPosition); View itemView = llm.findViewByPosition(itemPosition); Rect itemRect = new Rect(itemView.getLeft(), itemView.getTop(), itemView.getRight(), itemView.getBottom()); if (isVertical) {//垂直布局, 还需要靠对齐方式 drawVerticalItem(c, itemRect, itemPosition, translateX(parentRect), parentRect.exactCenterY()); } else {//水平布局 drawHorizontalItem(c, itemRect, itemPosition, parentRect.exactCenterX(), parentRect.exactCenterY()); } } drawDivider(c, parentRect, isVertical); }
View lastChild = rv.getChildAt(rv.getChildCount() - 1); return (rv.getAdapter().getItemCount() - 1) * lm.getDecoratedMeasuredHeight(lastChild) + lm.getDecoratedBottom(lastChild) - rv.getBottom();
mCenterPivot = lm.getOrientation() == LinearLayoutManager.HORIZONTAL ? ( recyclerView.getLeft() + recyclerView.getRight() ) : ( recyclerView.getTop() + recyclerView.getBottom() );
View lastChild = rv.getChildAt(rv.getChildCount() - 1); return (rv.getAdapter().getItemCount() - 1) * lm.getDecoratedMeasuredHeight(lastChild) + lm.getDecoratedBottom(lastChild) - rv.getBottom();