Last active
September 11, 2020 10:17
-
-
Save Gnzlt/51a811f51eaf6d350dde2de3880b0c64 to your computer and use it in GitHub Desktop.
Android ViewPager2 extension function to scroll to the last position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.utils | |
import androidx.viewpager2.widget.ViewPager2 | |
object ViewPagerUtils { | |
fun ViewPager2.scrollToLastPosition() { | |
val lastPosition = adapter?.itemCount?.minus(1) ?: 0 | |
if (currentItem != lastPosition) { | |
currentItem = lastPosition | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment