@NonNull @Override public Animator[] getAnimators(@NonNull View view) { float mOriginalY = mRecyclerView.getLayoutManager().getDecoratedTop(view); float mDeltaY = mRecyclerView.getHeight() - mOriginalY; return new Animator[]{ObjectAnimator.ofFloat(view, TRANSLATION_Y, mDeltaY, 0)}; } }
private void retrieveItemPosition(final RecyclerView.ViewHolder holder) { mOriginalY = mRecyclerView.getLayoutManager().getDecoratedTop(holder.itemView); mDeltaY = mRecyclerView.getHeight() - mOriginalY; }
View firstChild = rv.getChildAt(0); return rv.getChildLayoutPosition(firstChild) * lm.getDecoratedMeasuredHeight(firstChild) - lm.getDecoratedTop(firstChild); } else { View lastChild = rv.getChildAt(rv.getChildCount() - 1);
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; }
@Override public int getCurrentScrollY() { // Return early if there are no items or we haven't been measured List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems(); if (items.isEmpty() || mNumAppsPerRow == 0 || getChildCount() == 0) { return -1; } // Calculate the y and offset for the item View child = getChildAt(0); int position = getChildLayoutPosition(child); if (position == NO_POSITION) { return -1; } return getCurrentScrollY(position, getLayoutManager().getDecoratedTop(child)); }
@Override public int calculateDyToMakeVisible(View view, int snapPreference) { final RecyclerView.LayoutManager layoutManager = getLayoutManager(); if (layoutManager == null || !layoutManager.canScrollVertically()) { return 0; } final int adapterPosition = getPosition(view); final int topOffset = getPositionSectionHeaderHeight(adapterPosition); final int top = layoutManager.getDecoratedTop(view); final int bottom = layoutManager.getDecoratedBottom(view); final int start = layoutManager.getPaddingTop() + topOffset; final int end = layoutManager.getHeight() - layoutManager.getPaddingBottom(); return calculateDtToFit(top, bottom, start, end, snapPreference); } };
@Override public int getCurrentScrollY() { // Return early if there are no items or we haven't been measured List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems(); if (items.isEmpty() || mNumAppsPerRow == 0 || getChildCount() == 0) { return -1; } // Calculate the y and offset for the item View child = getChildAt(0); int position = getChildPosition(child); if (position == NO_POSITION) { return -1; } return getCurrentScrollY(position, getLayoutManager().getDecoratedTop(child)); }
@Override public int calculateDyToMakeVisible(View view, int snapPreference) { final RecyclerView.LayoutManager layoutManager = getLayoutManager(); if (layoutManager == null || !layoutManager.canScrollVertically()) { return 0; } final int adapterPosition = getPosition(view); final int topOffset = getPositionSectionHeaderHeight(adapterPosition); final int top = layoutManager.getDecoratedTop(view); final int bottom = layoutManager.getDecoratedBottom(view); final int start = layoutManager.getPaddingTop() + topOffset; final int end = layoutManager.getHeight() - layoutManager.getPaddingBottom(); return calculateDtToFit(top, bottom, start, end, snapPreference); } };
@Override public int getCurrentScrollY() { // Return early if there are no items or we haven't been measured List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems(); if (items.isEmpty() || mNumAppsPerRow == 0 || getChildCount() == 0) { return -1; } // Calculate the y and offset for the item View child = getChildAt(0); int position = getChildPosition(child); if (position == NO_POSITION) { return -1; } return getCurrentScrollY(position, getLayoutManager().getDecoratedTop(child)); }
private void retrieveItemPosition(final RecyclerView.ViewHolder holder) { mOriginalY = mRecyclerView.getLayoutManager().getDecoratedTop(holder.itemView); mDeltaY = mRecyclerView.getHeight() - mOriginalY; }
@Override public int getCurrentScrollY() { // Skip early if widgets are not bound. if (isModelNotReady() || getChildCount() == 0) { return -1; } View child = getChildAt(0); int rowIndex = getChildPosition(child); int y = (child.getMeasuredHeight() * rowIndex); int offset = getLayoutManager().getDecoratedTop(child); return getPaddingTop() + y - offset; }
@NonNull @Override public Animator[] getAnimators(@NonNull View view) { float mOriginalY = mRecyclerView.getLayoutManager().getDecoratedTop(view); float mDeltaY = mRecyclerView.getHeight() - mOriginalY; return new Animator[]{ObjectAnimator.ofFloat(view, TRANSLATION_Y, mDeltaY, 0)}; } }
@Override public int getDecoratedStart(View view) { final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams(); return mLayoutManager.getDecoratedTop(view) - params.topMargin; }
@Override public int getCurrentScrollY() { // Skip early if widgets are not bound. if (isModelNotReady() || getChildCount() == 0) { return -1; } View child = getChildAt(0); int rowIndex = getChildLayoutPosition(child); int y = (child.getMeasuredHeight() * rowIndex); int offset = getLayoutManager().getDecoratedTop(child); return getPaddingTop() + y - offset; }
@Override public int getCurrentScrollY() { // Skip early if widgets are not bound. if (isModelNotReady() || getChildCount() == 0) { return -1; } View child = getChildAt(0); int rowIndex = getChildPosition(child); int y = (child.getMeasuredHeight() * rowIndex); int offset = getLayoutManager().getDecoratedTop(child); return getPaddingTop() + y - offset; }
@Override public int getDecoratedStart(View view) { final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams(); return mLayoutManager.getDecoratedTop(view) - params.topMargin; }
@Override public int getDecoratedStart(View view) { final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams(); return mLayoutManager.getDecoratedTop(view) - params.topMargin; }
/** * Returns the current scroll state of the apps rows. */ @SuppressWarnings("unchecked") private void getCurScrollState(ScrollPositionState stateOut) { stateOut.rowIndex = -1; stateOut.rowTopOffset = -1; stateOut.rowHeight = -1; int itemCount = getAdapter().getItemCount(); // Return early if there are no items, or no children. if (itemCount == 0 || getChildCount() == 0) { return; } View child = getChildAt(0); stateOut.rowIndex = getChildAdapterPosition(child); if (getLayoutManager() instanceof GridLayoutManager) { stateOut.rowIndex = stateOut.rowIndex / ((GridLayoutManager) getLayoutManager()).getSpanCount(); } if (getAdapter() instanceof MeasurableAdapter) { stateOut.rowTopOffset = getLayoutManager().getDecoratedTop(child); stateOut.rowHeight = ((MeasurableAdapter) getAdapter()).getViewTypeHeight(this, findViewHolderForAdapterPosition(stateOut.rowIndex), getAdapter().getItemViewType(stateOut.rowIndex)); } else { stateOut.rowTopOffset = getLayoutManager().getDecoratedTop(child); stateOut.rowHeight = child.getHeight() + getLayoutManager().getTopDecorationHeight(child) + getLayoutManager().getBottomDecorationHeight(child); } }
- layoutManager.getPaddingBottom() - layoutManager.getDecoratedBottom(firstView) : layoutManager.getDecoratedTop(firstView) - layoutManager.getPaddingTop();
@Override public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) { if (parent.isAnimating()) return; final int childCount = parent.getChildCount(); final RecyclerView.LayoutManager lm = parent.getLayoutManager(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child); if (requiresDivider(viewHolder)) { final int right = lm.getDecoratedRight(child); final int bottom = lm.getDecoratedBottom(child); // draw the bottom divider canvas.drawRect(lm.getDecoratedLeft(child), bottom - dividerSize, right, bottom, paint); // draw the right edge divider canvas.drawRect(right - dividerSize, lm.getDecoratedTop(child), right, bottom - dividerSize, paint); } } }