/** * Attach the tracker. * * @param recyclerView The recyclerview that the EpoxyController has its adapter added to. */ public void attach(@NonNull RecyclerView recyclerView) { attachedRecyclerView = recyclerView; recyclerView.addOnScrollListener(this.listener); recyclerView.addOnLayoutChangeListener(this.listener); recyclerView.addOnChildAttachStateChangeListener(this.listener); setTracker(recyclerView, this); }
@Override public void onActivityReenter(int resultCode, Intent data) { if (data == null || resultCode != RESULT_OK || !data.hasExtra(Activities.Dribbble.Shot.RESULT_EXTRA_SHOT_ID)) return; // When reentering, if the shared element is no longer on screen (e.g. after an // orientation change) then scroll it into view. final long sharedShotId = data.getLongExtra(Activities.Dribbble.Shot.RESULT_EXTRA_SHOT_ID, -1L); if (sharedShotId != -1L // returning from a shot && adapter.getDataItemCount() > 0 // grid populated && grid.findViewHolderForItemId(sharedShotId) == null) { // view not attached final int position = adapter.getItemPosition(sharedShotId); if (position == RecyclerView.NO_POSITION) return; // delay the transition until our shared element is on-screen i.e. has been laid out postponeEnterTransition(); grid.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int l, int t, int r, int b, int oL, int oT, int oR, int oB) { grid.removeOnLayoutChangeListener(this); startPostponedEnterTransition(); } }); grid.scrollToPosition(position); toolbar.setTranslationZ(-1f); } }
recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
/** * Scrolls the recycler view to show the last viewed item in the grid. This is important when * navigating back from the grid. */ private void scrollToPosition() { recyclerView.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { recyclerView.removeOnLayoutChangeListener(this); final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); View viewAtPosition = layoutManager.findViewByPosition(MainActivity.currentPosition); // Scroll to position if the view for the current position is null (not currently part of // layout manager children), or it's not completely visible. if (viewAtPosition == null || layoutManager .isViewPartiallyVisible(viewAtPosition, false, true)) { recyclerView.post(() -> layoutManager.scrollToPosition(MainActivity.currentPosition)); } } }); }
public void setRecyclerView(RecyclerView recyclerView) { if (mRecyclerView != null) { mRecyclerView.removeOnScrollListener(mScrollListener); mRecyclerView.removeOnLayoutChangeListener(mLayoutChangeListener); } mRecyclerView = recyclerView; recyclerView.addOnScrollListener(mScrollListener); recyclerView.addOnLayoutChangeListener(mLayoutChangeListener); registerAdapterDataObserver(); }
mRecyclerView.addOnLayoutChangeListener((View v, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7) -> updateOverscrollMode());
mRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { int oldPadding; @Override