Share
Embed
How to implement custom LayoutManager
Moyuru Aizawa
March 08, 2019
Transcript
61 slides
-
MoyuruAizawa Moyuru Aizawa Software engineer of CATS Div. CyberAgent Inc.
Previously at Pairs Div. Eureka Inc. -
‣ ؔػೳ͕ଟ͍ͷͰ͔ͳΓେม ‣ ϨΠΞτͷෳࡶ͞Λ૿͢ཁૉ ‣ 0SJFOUBUJPO 7FSUJDBM-BZPVU)PSJ[POUBM-BZPVU ‣ 3FWFSTF-BZPVU
‣ -5335- -BZPVU.BOBHFSͷ࣮େม -
‣ PO-BZPVU$IJMESFO ‣ TDSPMM7FSUJDBMMZ#ZTDSPMM)PSJ[POUBMMZ#Z ‣ TDSPMM5P ‣ TNPPUI4DSPMM5P ‣ DPNQVUF7FSUJDBM4DSPMM&YUFOUDPNQVUF)PSJ[POUBM4DSPMM&YUFOU
‣ DPNQVUF7FSUJDBM4DSPMM0GGTFUDPNQVUF)PSJ[POUBM4DSPMM0GGTFU ‣ DPNQVUF7FSUJDBM4DSPMM3BOHFDPNQVUF)PSJ[POUBM4DSPMM3BOHF ‣ *UFN1SFGFUDI ‣ *UFN%FDPSBUJPOT ‣ *UFN"OJNBUPST ‣ 1SFEJDUJWF"OJNBUJPOT ‣ ʜ -BZPVU.BOBHFSͷؔػೳ -
‣ PO-BZPVU$IJMESFO ‣ TDSPMM7FSUJDBMMZ#ZTDSPMM)PSJ[POUBMMZ#Z ‣ TDSPMM5P ‣ TNPPUI4DSPMM5P ‣ DPNQVUF7FSUJDBM4DSPMM&YUFOUDPNQVUF)PSJ[POUBM4DSPMM&YUFOU
‣ DPNQVUF7FSUJDBM4DSPMM0GGTFUDPNQVUF)PSJ[POUBM4DSPMM0GGTFU ‣ DPNQVUF7FSUJDBM4DSPMM3BOHFDPNQVUF)PSJ[POUBM4DSPMM3BOHF ‣ *UFN1SFGFUDI ‣ *UFN%FDPSBUJPOT ‣ *UFN"OJNBUPST ‣ 1SFEJDUJWF"OJNBUJPOT ‣ ʜ -BZPVU.BOBHFSͷؔػೳ -
‣ PO-BZPVU$IJMESFO ‣ TDSPMM7FSUJDBMMZ#ZTDSPMM)PSJ[POUBMMZ#Z ‣ TDSPMM5P ‣ TNPPUI4DSPMM5P ‣ DPNQVUF7FSUJDBM4DSPMM&YUFOUDPNQVUF)PSJ[POUBM4DSPMM&YUFOU
‣ DPNQVUF7FSUJDBM4DSPMM0GGTFUDPNQVUF)PSJ[POUBM4DSPMM0GGTFU ‣ DPNQVUF7FSUJDBM4DSPMM3BOHFDPNQVUF)PSJ[POUBM4DSPMM3BOHF ‣ *UFN1SFGFUDI ‣ *UFN%FDPSBUJPOT ‣ *UFN"OJNBUPST ‣ 1SFEJDUJWF"OJNBUJPOT ‣ ʜ -BZPVU.BOBHFSͷؔػೳ -
‣ PO-BZPVU$IJMESFO ‣ TDSPMM7FSUJDBMMZ#ZTDSPMM)PSJ[POUBMMZ#Z ‣ TDSPMM5P ‣ TNPPUI4DSPMM5P ‣ DPNQVUF7FSUJDBM4DSPMM&YUFOUDPNQVUF)PSJ[POUBM4DSPMM&YUFOU
‣ DPNQVUF7FSUJDBM4DSPMM0GGTFUDPNQVUF)PSJ[POUBM4DSPMM0GGTFU ‣ DPNQVUF7FSUJDBM4DSPMM3BOHFDPNQVUF)PSJ[POUBM4DSPMM3BOHF ‣ *UFN1SFGFUDI ‣ *UFN%FDPSBUJPOT ‣ *UFN"OJNBUPST ‣ 1SFEJDUJWF"OJNBUJPOT ‣ ʜ -BZPVU.BOBHFSͷؔػೳ -
‣ PO-BZPVU$IJMESFO ‣ TDSPMM7FSUJDBMMZ#ZTDSPMM)PSJ[POUBMMZ#Z ‣ TDSPMM5P ‣ TNPPUI4DSPMM5P ‣ DPNQVUF7FSUJDBM4DSPMM&YUFOUDPNQVUF)PSJ[POUBM4DSPMM&YUFOU
‣ DPNQVUF7FSUJDBM4DSPMM0GGTFUDPNQVUF)PSJ[POUBM4DSPMM0GGTFU ‣ DPNQVUF7FSUJDBM4DSPMM3BOHFDPNQVUF)PSJ[POUBM4DSPMM3BOHF ‣ *UFN1SFGFUDI ‣ *UFN%FDPSBUJPOT ‣ *UFN"OJNBUPST ‣ 1SFEJDUJWF"OJNBUJPOT ‣ ʜ -BZPVU.BOBHFSͷؔػೳ -
‣ PO-BZPVU$IJMESFO ‣ TDSPMM7FSUJDBMMZ#ZTDSPMM)PSJ[POUBMMZ#Z ‣ TDSPMM5P ‣ TNPPUI4DSPMM5P ‣ DPNQVUF7FSUJDBM4DSPMM&YUFOUDPNQVUF)PSJ[POUBM4DSPMM&YUFOU
‣ DPNQVUF7FSUJDBM4DSPMM0GGTFUDPNQVUF)PSJ[POUBM4DSPMM0GGTFU ‣ DPNQVUF7FSUJDBM4DSPMM3BOHFDPNQVUF)PSJ[POUBM4DSPMM3BOHF ‣ *UFN1SFGFUDI ‣ *UFN%FDPSBUJPOT ‣ *UFN"OJNBUPST ‣ 1SFEJDUJWF"OJNBUJPOT ‣ ʜ -BZPVU.BOBHFSͷؔػೳ -
‣ PO-BZPVU$IJMESFO ‣ TDSPMM7FSUJDBMMZ#ZTDSPMM)PSJ[POUBMMZ#Z ‣ TDSPMM5P ‣ TNPPUI4DSPMM5P ‣ DPNQVUF7FSUJDBM4DSPMM&YUFOUDPNQVUF)PSJ[POUBM4DSPMM&YUFOU
‣ DPNQVUF7FSUJDBM4DSPMM0GGTFUDPNQVUF)PSJ[POUBM4DSPMM0GGTFU ‣ DPNQVUF7FSUJDBM4DSPMM3BOHFDPNQVUF)PSJ[POUBM4DSPMM3BOHF ‣ *UFN1SFGFUDI ‣ *UFN%FDPSBUJPOT ‣ *UFN"OJNBUPST ‣ 1SFEJDUJWF"OJNBUJPOT ‣ ʜ -BZPVU.BOBHFSͷؔػೳ -
private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):
Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO -
private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):
Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO -
private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):
Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO -
private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):
Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO -
private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):
Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO -
private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):
Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO -
private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):
Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO -
private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):
Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO -
private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):
Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO -
private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):
Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO -
private fun fillChunk(startPosition: Int, startY: Int, isAppend: Boolean, recycler: Recycler)
{ val remainingSpace = if (isAppend) parentBottom - startY else startY - parentTop var offsetY = startY val range = if (isAppend) startPosition until itemCount else startPosition downTo 0 for (position in range) { val height = addRow(position, offsetY, isAppend, recycler) offsetY += if (isAppend) height else -height val consumed = abs(offsetY - startY) if (consumed > remainingSpace) break } } PO-BZPVU$IJMESFO -
private fun fillChunk(startPosition: Int, startY: Int, isAppend: Boolean, recycler: Recycler)
{ val remainingSpace = if (isAppend) parentBottom - startY else startY - parentTop var offsetY = startY val range = if (isAppend) startPosition until itemCount else startPosition downTo 0 for (position in range) { val height = addRow(position, offsetY, isAppend, recycler) offsetY += if (isAppend) height else -height val consumed = abs(offsetY - startY) if (consumed > remainingSpace) break } } PO-BZPVU$IJMESFO -
private fun fillChunk(startPosition: Int, startY: Int, isAppend: Boolean, recycler: Recycler)
{ val remainingSpace = if (isAppend) parentBottom - startY else startY - parentTop var offsetY = startY val range = if (isAppend) startPosition until itemCount else startPosition downTo 0 for (position in range) { val height = addRow(position, offsetY, isAppend, recycler) offsetY += if (isAppend) height else -height val consumed = abs(offsetY - startY) if (consumed > remainingSpace) break } } PO-BZPVU$IJMESFO -
private fun fillChunk(startPosition: Int, startY: Int, isAppend: Boolean, recycler: Recycler)
{ val remainingSpace = if (isAppend) parentBottom - startY else startY - parentTop var offsetY = startY val range = if (isAppend) startPosition until itemCount else startPosition downTo 0 for (position in range) { val height = addRow(position, offsetY, isAppend, recycler) offsetY += if (isAppend) height else -height val consumed = abs(offsetY - startY) if (consumed > remainingSpace) break } } PO-BZPVU$IJMESFO -
override fun onLayoutChildren(recycler: Recycler, state: State) { if (itemCount ==
0) { detachAndScrapAttachedViews(recycler) return } val restoredFirstVisibleView = getChildAt(0) val restoredPosition = restoredFirstVisibleView?.adapterPosition val restoredTop = restoredFirstVisibleView?.let(this::getDecoratedTop) if (childCount > 0) detachAndScrapAttachedViews(recycler) fillChunk(restoredPosition ?: 0, restoredTop ?: parentTop, isAppend = true, recycler = recycler) } PO-BZPVU$IJMESFO -
override fun onLayoutChildren(recycler: Recycler, state: State) { if (itemCount ==
0) { detachAndScrapAttachedViews(recycler) return } val restoredFirstVisibleView = getChildAt(0) val restoredPosition = restoredFirstVisibleView?.adapterPosition val restoredTop = restoredFirstVisibleView?.let(this::getDecoratedTop) if (childCount > 0) detachAndScrapAttachedViews(recycler) fillChunk(restoredPosition ?: 0, restoredTop ?: parentTop, isAppend = true, recycler = recycler) } PO-BZPVU$IJMESFO -
override fun onLayoutChildren(recycler: Recycler, state: State) { if (itemCount ==
0) { detachAndScrapAttachedViews(recycler) return } val restoredFirstVisibleView = getChildAt(0) val restoredPosition = restoredFirstVisibleView?.adapterPosition val restoredTop = restoredFirstVisibleView?.let(this::getDecoratedTop) if (childCount > 0) detachAndScrapAttachedViews(recycler) fillChunk(restoredPosition ?: 0, restoredTop ?: parentTop, isAppend = true, recycler = recycler) } PO-BZPVU$IJMESFO -
override fun onLayoutChildren(recycler: Recycler, state: State) { if (itemCount ==
0) { detachAndScrapAttachedViews(recycler) return } val restoredFirstVisibleView = getChildAt(0) val restoredPosition = restoredFirstVisibleView?.adapterPosition val restoredTop = restoredFirstVisibleView?.let(this::getDecoratedTop) if (childCount > 0) detachAndScrapAttachedViews(recycler) fillChunk(restoredPosition ?: 0, restoredTop ?: parentTop, isAppend = true, recycler = recycler) } PO-BZPVU$IJMESFO -
override fun onSaveInstanceState(): Parcelable? { val firstVisibleItem = getChildAt(0) ?:
return null return SavedState(firstVisibleItem.adapterPosition, getDecoratedTop(firstVisibleItem)) } override fun onRestoreInstanceState(state: Parcelable?) { savedState = state as? SavedState } PO-BZPVU$IJMESFO -
val restoredFirstVisibleView = getChildAt(0) val restoredPosition = savedState?.firstVisibleItemPosition ?: restoredFirstVisibleView?.adapterPosition
val restoredTop = savedState?.firstVisibleItemTop ?: restoredFirstVisibleView?.let(this::getDecoratedTop) if (childCount > 0) detachAndScrapAttachedViews(recycler) if (restoredPosition != null && restoredTop != null && restoredPosition < itemCount) fillChunk(restoredPosition, restoredTop, isAppend = true, recycler = recycler) else fillChunk(0, parentTop, isAppend = true, recycler = recycler) PO-BZPVU$IJMESFO -
private fun calculateActualDy(dy: Int): Int { if (dy == 0)
return 0 return if (dy > 0) { // up swipe val lastView = getChildAt(childCount - 1) ?: return 0 val bottom = getDecoratedBottom(lastView) if (lastView.adapterPosition == itemCount - 1) if (bottom == parentBottom) 0 else min(bottom - parentBottom, dy) else dy } else { val firstView = getChildAt(0) ?: return 0 val top = getDecoratedTop(firstView) if (firstView.adapterPosition == 0) if (top == parentTop) 0 else max(top - parentTop, dy) else dy } } TDSPMM7FSUJDBMMZ#Z -
private fun calculateActualDy(dy: Int): Int { if (dy == 0)
return 0 return if (dy > 0) { // up swipe val lastView = getChildAt(childCount - 1) ?: return 0 val bottom = getDecoratedBottom(lastView) if (lastView.adapterPosition == itemCount - 1) if (bottom == parentBottom) 0 else min(bottom - parentBottom, dy) else dy } else { val firstView = getChildAt(0) ?: return 0 val top = getDecoratedTop(firstView) if (firstView.adapterPosition == 0) if (top == parentTop) 0 else max(top - parentTop, dy) else dy } } TDSPMM7FSUJDBMMZ#Z -
private fun calculateActualDy(dy: Int): Int { if (dy == 0)
return 0 return if (dy > 0) { // up swipe val lastView = getChildAt(childCount - 1) ?: return 0 val bottom = getDecoratedBottom(lastView) if (lastView.adapterPosition == itemCount - 1) if (bottom == parentBottom) 0 else min(bottom - parentBottom, dy) else dy } else { val firstView = getChildAt(0) ?: return 0 val top = getDecoratedTop(firstView) if (firstView.adapterPosition == 0) if (top == parentTop) 0 else max(top - parentTop, dy) else dy } } TDSPMM7FSUJDBMMZ#Z -
private fun calculateActualDy(dy: Int): Int { if (dy == 0)
return 0 return if (dy > 0) { // up swipe val lastView = getChildAt(childCount - 1) ?: return 0 val bottom = getDecoratedBottom(lastView) if (lastView.adapterPosition == itemCount - 1) if (bottom == parentBottom) 0 else min(bottom - parentBottom, dy) else dy } else { val firstView = getChildAt(0) ?: return 0 val top = getDecoratedTop(firstView) if (firstView.adapterPosition == 0) if (top == parentTop) 0 else max(top - parentTop, dy) else dy } } TDSPMM7FSUJDBMMZ#Z -
private fun recycleTop(recycler: Recycler) { children.forEach { if (getDecoratedBottom(it) <
parentTop) removeAndRecycleView(it, recycler) else return } } TDSPMM7FSUJDBMMZ#Z -
private fun recycleTop(recycler: Recycler) { children.forEach { if (getDecoratedBottom(it) <
parentTop) removeAndRecycleView(it, recycler) else return } } TDSPMM7FSUJDBMMZ#Z -
private fun recycleTop(recycler: Recycler) { children.forEach { if (getDecoratedBottom(it) <
parentTop) removeAndRecycleView(it, recycler) else return } } TDSPMM7FSUJDBMMZ#Z -
override fun scrollVerticallyBy(dy: Int, recycler: Recycler, state: State): Int {
val actualDy = calculateActualDy(dy) if (actualDy == 0) return 0 offsetChildrenVertical(-actualDy) if (actualDy > 0) { recycleTop(recycler) val lastView = getChildAt(childCount - 1) ?: return 0 val bottom = getDecoratedBottom(lastView) if (bottom < parentBottom) fillChunk(lastView.adapterPosition + 1, bottom, true, recycler) } else { … } return actualDy } TDSPMM7FSUJDBMMZ#Z -
override fun scrollVerticallyBy(dy: Int, recycler: Recycler, state: State): Int {
val actualDy = calculateActualDy(dy) if (actualDy == 0) return 0 offsetChildrenVertical(-actualDy) if (actualDy > 0) { recycleTop(recycler) val lastView = getChildAt(childCount - 1) ?: return 0 val bottom = getDecoratedBottom(lastView) if (bottom < parentBottom) fillChunk(lastView.adapterPosition + 1, bottom, true, recycler) } else { … } return actualDy } TDSPMM7FSUJDBMMZ#Z -
override fun scrollVerticallyBy(dy: Int, recycler: Recycler, state: State): Int {
val actualDy = calculateActualDy(dy) if (actualDy == 0) return 0 offsetChildrenVertical(-actualDy) if (actualDy > 0) { recycleTop(recycler) val lastView = getChildAt(childCount - 1) ?: return 0 val bottom = getDecoratedBottom(lastView) if (bottom < parentBottom) fillChunk(lastView.adapterPosition + 1, bottom, true, recycler) } else { … } return actualDy } TDSPMM7FSUJDBMMZ#Z -
override fun scrollVerticallyBy(dy: Int, recycler: Recycler, state: State): Int {
val actualDy = calculateActualDy(dy) if (actualDy == 0) return 0 offsetChildrenVertical(-actualDy) if (actualDy > 0) { recycleTop(recycler) val lastView = getChildAt(childCount - 1) ?: return 0 val bottom = getDecoratedBottom(lastView) if (bottom < parentBottom) fillChunk(lastView.adapterPosition + 1, bottom, true, recycler) } else { … } return actualDy } TDSPMM7FSUJDBMMZ#Z -
override fun scrollVerticallyBy(dy: Int, recycler: Recycler, state: State): Int {
val actualDy = calculateActualDy(dy) if (actualDy == 0) return 0 offsetChildrenVertical(-actualDy) if (actualDy > 0) { recycleTop(recycler) val lastView = getChildAt(childCount - 1) ?: return 0 val bottom = getDecoratedBottom(lastView) if (bottom < parentBottom) fillChunk(lastView.adapterPosition + 1, bottom, true, recycler) } else { … } return actualDy } TDSPMM7FSUJDBMMZ#Z -
override fun scrollVerticallyBy(dy: Int, recycler: Recycler, state: State): Int {
val actualDy = calculateActualDy(dy) if (actualDy == 0) return 0 offsetChildrenVertical(-actualDy) if (actualDy > 0) { recycleTop(recycler) val lastView = getChildAt(childCount - 1) ?: return 0 val bottom = getDecoratedBottom(lastView) if (bottom < parentBottom) fillChunk(lastView.adapterPosition + 1, bottom, true, recycler) } else { … } return actualDy } TDSPMM7FSUJDBMMZ#Z -
override fun onLayoutChildren(recycler: Recycler, state: State) { … if (pendingScrollPosition
!= RecyclerView.NO_POSITION) { fillChunk(pendingScrollPosition, parentTop, true, recycler) val lastVisibleView = getChildAt(childCount - 1) ?: return val bottom = getDecoratedBottom(lastVisibleView) if (lastVisibleView.adapterPosition.isLast && bottom < parentBottom) fixLayoutGap() return } … } TDSPMM5P1PTJUJPO -
override fun onLayoutChildren(recycler: Recycler, state: State) { … if (pendingScrollPosition
!= RecyclerView.NO_POSITION) { fillChunk(pendingScrollPosition, parentTop, true, recycler) val lastVisibleView = getChildAt(childCount - 1) ?: return val bottom = getDecoratedBottom(lastVisibleView) if (lastVisibleView.adapterPosition.isLast && bottom < parentBottom) fixLayoutGap() return } … } TDSPMM5P1PTJUJPO -
override fun onLayoutChildren(recycler: Recycler, state: State) { … if (pendingScrollPosition
!= RecyclerView.NO_POSITION) { fillChunk(pendingScrollPosition, parentTop, true, recycler) val lastVisibleView = getChildAt(childCount - 1) ?: return val bottom = getDecoratedBottom(lastVisibleView) if (lastVisibleView.adapterPosition.isLast && bottom < parentBottom) fixLayoutGap() return } … } TDSPMM5P1PTJUJPO 99 -
override fun onLayoutChildren(recycler: Recycler, state: State) { … if (pendingScrollPosition
!= RecyclerView.NO_POSITION) { fillChunk(pendingScrollPosition, parentTop, true, recycler) val lastVisibleView = getChildAt(childCount - 1) ?: return val bottom = getDecoratedBottom(lastVisibleView) if (lastVisibleView.adapterPosition.isLast && bottom < parentBottom) fixLayoutGap() return } … } TDSPMM5P1PTJUJPO 99 -
override fun onLayoutChildren(recycler: Recycler, state: State) { … if (pendingScrollPosition
!= RecyclerView.NO_POSITION) { fillChunk(pendingScrollPosition, parentTop, true, recycler) val lastVisibleView = getChildAt(childCount - 1) ?: return val bottom = getDecoratedBottom(lastVisibleView) if (lastVisibleView.adapterPosition.isLast && bottom < parentBottom) fixLayoutGap() return } … } TDSPMM5P1PTJUJPO 99 98 97 96 95