1

I have TabLayout setup with a ViewPager. When I select a tab the ViewPager scroll to the selected page with animation (showing all the pages in between current page and selected page). I want ViewPager to directly jump to the selected page.

I know I can use viewPager.setCurrentItem(1, false) to disable smoothScroll. But I want to change the default behavior to disable smoothScroll effect on ViewPager

Here is what I have done.

val mSectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager) vp!!.adapter = mSectionsPagerAdapter vp!!.addOnPageChangeListener(object: ViewPager.OnPageChangeListener { override fun onPageScrollStateChanged(state: Int) { } override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { } override fun onPageSelected(position: Int) { when (position) { 0 -> supportActionBar!!.title = "Page 1" 1 -> supportActionBar!!.title = "Page 2" 2 -> supportActionBar!!.title = "Page 3" 3 -> supportActionBar!!.title = "Page 4" } } }) tabLayout.setupWithViewPager(vp) 

1 Answer 1

0

You can subclass the ViewPager and make a custom ViewPager Please take a look at Toni's answer in this link: Disabling animation in ViewPager

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.