0

See next answer in so, but here simply I can determine that has changed page. How can i determine when a user is scrolling ViewPager?

Morozov
  • 4,968
  • 6
  • 39
  • 70

1 Answers1

1

You can attach an OnPageChangeListener to your ViewPager and override its methods. When the pager is scrolled, the method onPageScrolled is called while it's scrolled, so you can use that.

view_pager.addOnPageChangeListener(object : OnPageChangeListener {
            ...

            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int) 
            {
                Log.d("Debugging", "Pager is now scrolling: $positionOffset")
            }

            ...

        })

You can also use the method onPageScrollStateChanged from OnPageChangeListener to find out when the scrolling state is changing. The state param of that method can be SCROLL_STATE_IDLE, SCROLL_STATE_DRAGGING, SCROLL_STATE_SETTLING.