Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
initViewPager()
}
private fun initViewPager() {
val pageAdapter = PageAdapter(listOf(Item(Color.RED), Item(Color.BLUE), Item(Color.GREEN)))
viewPager2.offscreenPageLimit = 2
viewPager2.orientation = ViewPager2.ORIENTATION_VERTICAL
viewPager2.adapter = pageAdapter
viewPager2.currentItem = pageAdapter.getMiddlePosition()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment