protected void onTabScrolled(int position, float positionOffset) { View scrollView = mLayoutManager.findViewByPosition(position); View nextView = mLayoutManager.findViewByPosition(position + 1); if(scrollView != null && nextView != null){ int width_scroll = scrollView.getMeasuredWidth(); int width_next = nextView.getMeasuredWidth(); float distance = (width_scroll + width_next) / 2f; int width = (int)(width_scroll + (width_next - width_scroll) * positionOffset + 0.5f); int offset = (int)(scrollView.getLeft() + width_scroll / 2f + distance * positionOffset - width / 2f + 0.5f); updateIndicator(offset, width); } }
/** * RecyclerView位移事件监听, view大小随位移事件变化 */ private void onScrolledChangedCallback() { int offset = mCurrentItemOffset - mCurrentItemPos * mOnePageWidth; float percent = (float) Math.max(Math.abs(offset) * 1.0 / mOnePageWidth, 0.0001); LogUtils.d(String.format("offset=%s, percent=%s", offset, percent)); View leftView = null; View currentView; View rightView = null; if (mCurrentItemPos > 0) { leftView = mRecyclerView.getLayoutManager().findViewByPosition(mCurrentItemPos - 1); } currentView = mRecyclerView.getLayoutManager().findViewByPosition(mCurrentItemPos); if (mCurrentItemPos < mRecyclerView.getAdapter().getItemCount() - 1) { rightView = mRecyclerView.getLayoutManager().findViewByPosition(mCurrentItemPos + 1); } if (leftView != null) { // y = (1 - mScale)x + mScale leftView.setScaleY((1 - mScale) * percent + mScale); } if (currentView != null) { // y = (mScale - 1)x + 1 currentView.setScaleY((mScale - 1) * percent + 1); } if (rightView != null) { // y = (1 - mScale)x + mScale rightView.setScaleY((1 - mScale) * percent + mScale); } }
if (isEditMode) { RecyclerView recyclerView = ((RecyclerView) parent); View targetView = recyclerView.getLayoutManager().findViewByPosition(mMyChannelItems.size() + COUNT_PRE_OTHER_HEADER); View currentView = recyclerView.getLayoutManager().findViewByPosition(position); View preTargetView = recyclerView.getLayoutManager().findViewByPosition(mMyChannelItems.size() + COUNT_PRE_OTHER_HEADER - 1); targetX = preTargetView.getLeft(); targetY = preTargetView.getTop(); if (view1 == recyclerView.getLayoutManager().findViewByPosition(0)) { TextView tvBtnEdit = view1.findViewById(R.id.tv_btn_edit); tvBtnEdit.setText(R.string.finish); int currentPosition = otherHolder.getAdapterPosition(); View currentView = manager.findViewByPosition(currentPosition); View preTargetView = manager.findViewByPosition(mMyChannelItems.size() - 1 + COUNT_PRE_MY_HEADER); View targetView = manager.findViewByPosition(targetPosition); targetX = targetView.getLeft(); targetY = targetView.getTop();
protected int getTopOrBottomPosition(int side, RecyclerView.LayoutManager layoutManager, int position, int first, int last) { if (position < first) { return Integer.MIN_VALUE; } else if (position > last) { return Integer.MAX_VALUE; } else { View view = layoutManager.findViewByPosition(position); if (side == TOP) { return view.getTop(); } else if (side == BOTTOM) { return view.getBottom(); } else { return 0; } } }
@Override public View findViewByPosition(int position) { return super.findViewByPosition(calculateRealPosition(position)); }
@Override public View findSnapView(RecyclerView.LayoutManager layoutManager) { if (layoutManager instanceof LadderLayoutManager) { int pos = ((LadderLayoutManager) layoutManager).getFixedScrollPosition( mDirection, mDirection != 0 ? 0.8f : 0.5f); mDirection = 0; if (pos != RecyclerView.NO_POSITION) { return layoutManager.findViewByPosition(pos); } } return null; } }
@Override public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) { super.onMapSharedElements(names, sharedElements); if (sharedElements.isEmpty()) { View view = recyclerView.getLayoutManager().findViewByPosition(viewPosition); if (view != null) { sharedElements.put(names.get(0), view.findViewById(R.id.circleView)); } } } });
@Override public void onGlobalLayout() { View addView = mRecyclerView.getLayoutManager().findViewByPosition(focusPosition); if (addView != null) { addView.requestFocus(); mRecyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } });
private void recoverFocus() { View saveFocusView = getLayoutManager().findViewByPosition(mSaveFocusPosition); if (saveFocusView != null) { saveFocusView.requestFocus(); } }
int currentPosition = helper.getAdapterPosition() - getHeaderLayoutCount(); View targetView = mRecyclerView.getLayoutManager().findViewByPosition(otherFirstPosition); View currentView = mRecyclerView.getLayoutManager().findViewByPosition(currentPosition);
int currentPosition = helper.getAdapterPosition() - getHeaderLayoutCount(); View targetView = mRecyclerView.getLayoutManager().findViewByPosition(myLastPosition); View currentView = mRecyclerView.getLayoutManager().findViewByPosition(currentPosition); View lastFourthView = mRecyclerView.getLayoutManager().findViewByPosition(getMyLastPosition() - 3);
for (int i = firstVisiblePosition; i <= lastVisiblePosition; i++) { if (mHasStickyHeader.isSticky(i)) { final View nextStickyHeader = mLayoutManager.findViewByPosition(i); final int offsetBetweenStickyHeaders = nextStickyHeader.getTop() - mSectionsRecyclerView.getStickyHeader().getBottom()
final View firstView = layoutManager.findViewByPosition(mCurrentFirstVisiblePosition);
private View findStartView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) { /** * 0,1,2,3 4,5,6,7 8,9,10,11 */ if (layoutManager instanceof LinearLayoutManager) { //找出第一个可见的ItemView的位置 int firstChildPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition(); if (firstChildPosition == RecyclerView.NO_POSITION) { return null; } //找到最后一个完全显示的ItemView,如果该ItemView是列表中的最后一个 //就说明列表已经滑动最后了,这时候就不应该根据第一个ItemView来对齐了 //要不然由于需要跟第一个ItemView对齐最后一个ItemView可能就一直无法完全显示, //所以这时候直接返回null表示不需要对齐 if (((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1) { return null; } View firstChildView = layoutManager.findViewByPosition(firstChildPosition); //如果第一个ItemView被遮住的长度没有超过一半,就取该ItemView作为snapView //超过一半,就把下一个ItemView作为snapView if (helper.getDecoratedEnd(firstChildView) >= helper.getDecoratedMeasurement(firstChildView) / 2 && helper.getDecoratedEnd(firstChildView) > 0) { return firstChildView; } else { return layoutManager.findViewByPosition(firstChildPosition + 1); } } else { return null; } }
protected void onTabScrollStateChanged(int state){ if(mCenterCurrentTab) { if (state == SCROLL_STATE_IDLE) { if (!mScrollingToCenter) { View v = mLayoutManager.findViewByPosition(mSelectedPosition); if (v != null) { int viewCenter = (v.getLeft() + v.getRight()) / 2; int parentCenter = (getLeft() + getPaddingLeft() + getRight() - getPaddingRight()) / 2; int scrollNeeded = viewCenter - parentCenter; if (scrollNeeded != 0) { smoothScrollBy(scrollNeeded, 0); mScrollingToCenter = true; } } } } if (state == SCROLL_STATE_DRAGGING || state == SCROLL_STATE_SETTLING) mScrollingToCenter = false; } if(state == ViewPager.SCROLL_STATE_IDLE){ mScrolling = false; View v = mLayoutManager.findViewByPosition(mSelectedPosition); updateIndicator(v); } else mScrolling = true; }
/** * Set the current tab of this TabIndicatorView. * @param position The position of current tab. */ public void setCurrentTab(int position) { if(mSelectedPosition != position){ View v = mLayoutManager.findViewByPosition(mSelectedPosition); if(v != null) ((Checkable)v).setChecked(false); } mSelectedPosition = position; View v = mLayoutManager.findViewByPosition(mSelectedPosition); if(v != null) ((Checkable)v).setChecked(true); animateToTab(position); }
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { updateIndicator(mLayoutManager.findViewByPosition(mSelectedPosition)); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); updateIndicator(mLayoutManager.findViewByPosition(mSelectedPosition)); }
public void run() { View v = mLayoutManager.findViewByPosition(position); if(!mScrolling) updateIndicator(v); smoothScrollToPosition(mSelectedPosition); mTabAnimSelector = null; } };
@Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_IDLE) { updateIndicator(mLayoutManager.findViewByPosition(mSelectedPosition)); } }