title: How to scroll a sync'd up MotionLayout+AppBarLayout programmatically?
body: <p>Consider the following <a href="https://github.com/android/views-widgets-samples/blob/main/ConstraintLayoutExamples/motionlayout/src/main/res/layout/motion_11_coordinatorlayout.xml" rel="nofollow noreferrer">Coordinator+AppBar</a>+<a href="https://github.com/android/views-widgets-samples/blob/main/ConstraintLayoutExamples/motionlayout/src/main/res/layout/motion_11_coordinatorlayout_header.xml" rel="nofollow noreferrer">MotionLayout</a> and its <a href="https://github.com/android/views-widgets-samples/blob/main/ConstraintLayoutExamples/motionlayout/src/main/res/xml/scene_11_header.xml" rel="nofollow noreferrer">MotionScene</a> from Google's demo. This creates a MotionLayout that sync's its Transition progress when the user is scrolling.</p>
  <p>Video Preview: <a href="https://i.imgur.com/1MnPB8R.mp4" rel="nofollow noreferrer">https://i.imgur.com/1MnPB8R.mp4</a></p>
  <p>However, I would like to do this in programmatically in Kotlin. Here are my failed attempts.</p>
  <pre><code>val motion = findViewById&lt;MotionLayout&gt;(R.id.constraintToolbar)
  motion.transitionToState(R.id.end)
  </code></pre>
  <p>The above would cause the MotionLayout to animate, but would immediately blink back to the <code>start</code> state once finished. The AppBarLayout also does not change height.</p>
  <pre><code>val appbar = findViewById&lt;AppBarLayout&gt;(R.id.app_bar)
  val scrollable = findViewById&lt;NestedScrollView&gt;(R.id.scrollable)
  val s = if(motion.progress==0F) appbar.totalScrollRange else 0
  scrollable.smoothScrollTo(0, s)
  </code></pre>
  <p>The above scrolls the NestedScrollView, but the AppBarLayout and MotionLayout does not receive the scroll events.</p>
  <pre><code>val s = if(motion.progress==0F)-appbar.totalScrollRange else 0
  val appbar = findViewById&lt;AppBarLayout&gt;(R.id.app_bar)
  appbar.scrollTo(0,s)
  appbar.offsetTopAndBottom(s)
  </code></pre>
  <p>The above shifts the AppBarLayout, breaking the layout completely.</p>
  <p>How do you trigger this scroll programmatically?</p>