//…Obtain the first visible item position… findFirstVisiblePosition(); detachAndScrapAttachedViews(recycler); for (…) { int nextPosition = …; View View = recycler.getViewForPosition(nextPosition); addView(view); measureChildWithMargins(view, …); layoutDecorated(view, …); } //Remove anything that is left behind final List<RecyclerView.ViewHolder> scrapList = recycler.getScrapList(); for (int i=0; i < scrapList.size(); i++) { final View removingView = scrapList.get(i); recycler.recycleView(removingView); } }
//…Obtain the first visible item position… findFirstVisiblePosition(); detachAndScrapAttachedViews(recycler); for (…) { int nextPosition = …; View View = recycler.getViewForPosition(nextPosition); addView(view); measureChildWithMargins(view, …); layoutDecorated(view, …); } //Remove anything that is left behind final List<RecyclerView.ViewHolder> scrapList = recycler.getScrapList(); for (int i=0; i < scrapList.size(); i++) { final View removingView = scrapList.get(i); recycler.recycleView(removingView); } }
//…Obtain the first visible item position… findFirstVisiblePosition(); detachAndScrapAttachedViews(recycler); for (…) { int nextPosition = …; View View = recycler.getViewForPosition(nextPosition); addView(view); measureChildWithMargins(view, …); layoutDecorated(view, …); } //Remove anything that is left behind final List<RecyclerView.ViewHolder> scrapList = recycler.getScrapList(); for (int i=0; i < scrapList.size(); i++) { final View removingView = scrapList.get(i); recycler.recycleView(removingView); } }
//…Obtain the first visible item position… findFirstVisiblePosition(); detachAndScrapAttachedViews(recycler); for (…) { int nextPosition = …; View View = recycler.getViewForPosition(nextPosition); addView(view); measureChildWithMargins(view, …); layoutDecorated(view, …); } //Remove anything that is left behind final List<RecyclerView.ViewHolder> scrapList = recycler.getScrapList(); for (int i=0; i < scrapList.size(); i++) { final View removingView = scrapList.get(i); recycler.recycleView(removingView); } }
canScrollVertically() canScrollHorizontally() Which axes enable scrolling? scrollHorizontallyBy() scrollVerticallyBy() Clamp supplied delta against boundary conditions Shift all views in the layout Trigger a FILL operation Report back actual distance scrolled
{ @Override public PointF computeScrollVectorForPosition(int targetPosition) { findFirstVisiblePosition(); final int rowOffset = …; final int columnOffset = …; return new PointF(columnOffset * stepWidth, rowOffset * stepHeight); } }; scroller.setTargetPosition(position); startSmoothScroll(scroller);
about animations… onLayoutChildren() [isPreLayout() == true] Note any removed views -> LayoutParams.isViewRemoved() Add extra views during FILL to cover space left behind onLayoutChildren() Place disappearing views off-screen
(state.isPreLayout()) { final View child = getChildAt(…); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.isItemRemoved()) { //Track and count view removals… } } //Clear all attached views into the recycle bin detachAndScrapAttachedViews(recycler); //Fill the grid for the initial layout of views fillGrid(…); //Anything left? Lay out for disappearing animation if (!state.isPreLayout() && !recycler.getScrapList().isEmpty()) { final List<RecyclerView.ViewHolder> scrapList = recycler.getScrapList(); //Laying out a scrap item removes it from the list… //Beware concurrent modification! … } }
(state.isPreLayout()) { final View child = getChildAt(…); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.isItemRemoved()) { //Track and count view removals… } } //Clear all attached views into the recycle bin detachAndScrapAttachedViews(recycler); //Fill the grid for the initial layout of views…account for extras fillGrid(…); //Anything left? Lay out for disappearing animation if (!state.isPreLayout() && !recycler.getScrapList().isEmpty()) { final List<RecyclerView.ViewHolder> scrapList = recycler.getScrapList(); //Laying out a scrap item removes it from the list… //Beware concurrent modification! … } }
(state.isPreLayout()) { final View child = getChildAt(…); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.isItemRemoved()) { //Track and count view removals… } } //Clear all attached views into the recycle bin detachAndScrapAttachedViews(recycler); //Fill the grid for the initial layout of views fillGrid(…); //Anything left? Lay out for disappearing animation if (!state.isPreLayout() && !recycler.getScrapList().isEmpty()) { final List<RecyclerView.ViewHolder> scrapList = recycler.getScrapList(); //Laying out a scrap item removes it from the list… //Beware concurrent modification! … } }