title: ViewPager2 setCurrentItem method throws error
body: <p>I'm using a <code>ViewPager2</code>, and I have a button that changes the current page of it to the second page, like this:</p>
  
  <pre><code>button_next.setOnClickListener {
              setup_view_pager.currentItem = 1
  }
  </code></pre>
  
  <p>It works until a page is swiped by hand and after that it throws this error:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: rs.ac.bg.matf.risk.matfasistent, PID: 32028
      java.lang.IllegalStateException: Expected position values between -1 and 1.
          at androidx.core.util.Preconditions.checkState(Preconditions.java:96)
          at androidx.viewpager2.widget.MarginPageTransformer.transformPage(MarginPageTransformer.java:56)
          at androidx.viewpager2.widget.PageTransformerAdapter.onPageScrolled(PageTransformerAdapter.java:72)
          at androidx.viewpager2.widget.CompositeOnPageChangeCallback.onPageScrolled(CompositeOnPageChangeCallback.java:59)
          at androidx.viewpager2.widget.ScrollEventAdapter.dispatchScrolled(ScrollEventAdapter.java:407)
          at androidx.viewpager2.widget.ScrollEventAdapter.onScrolled(ScrollEventAdapter.java:188)
          at androidx.recyclerview.widget.RecyclerView.dispatchOnScrolled(RecyclerView.java:5100)
          at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5265)
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1012)
          at android.view.Choreographer.doCallbacks(Choreographer.java:824)
          at android.view.Choreographer.doFrame(Choreographer.java:756)
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:998)
          at android.os.Handler.handleCallback(Handler.java:873)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:193)
          at android.app.ActivityThread.main(ActivityThread.java:6745)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
  </code></pre>
  
  <p>This happens only on these clicks, everything works fine when the fragments are swiped by hand. None of the locations of the error trace don't point to my code :(</p>
  
  <p>This is my adapter for the ViewPager:</p>
  
  <pre><code>class SetupAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle)
      : FragmentStateAdapter(fragmentManager, lifecycle) {
  
      override fun getItemCount() = 3
  
      override fun createFragment(position: Int): Fragment {
          return when (position) {
              0, 1, 2 -&gt; StudentSelectionFragment()
              else -&gt; throw IllegalStateException()
          }
      }
  }
  </code></pre>
  
  <p>And this is the whole relevant code of Activity:</p>
  
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          val adapter = SetupAdapter(supportFragmentManager, lifecycle)
  
          setup_view_pager.orientation = ViewPager2.ORIENTATION_HORIZONTAL
          setup_view_pager.adapter = adapter
          setup_view_pager.setPageTransformer(MarginPageTransformer(1500))
  
          button_next.setOnClickListener {
              setup_view_pager.setCurrentItem(1, true)
          }
      }
  </code></pre>