title: animate hide and show of an android button on scroll events
body: <p>Whats the best way to animate a button in android based on scroll events?</p>
  
  <p>I have a button which is located in the bottom right corner of the view and I'd like to animate the button to move below the bottom viewport when the user is scrolling down and up, if the user scrolls up. </p>
  
  <p>My Layout:</p>
  
  <p>I used the ObservableScrollView from this example (<a href="https://stackoverflow.com/questions/3948934/synchronise-scrollview-scroll-positions-android">Synchronise ScrollView scroll positions - android</a>)</p>
  
  <pre><code>&lt;RelativeLayout ...&gt;
      &lt;ObservableScrollView ...&gt; 
          &lt;LinearLayout ...&gt;
              &lt;!-- &lt;Items&gt; --&gt;
          &lt;/LinearLayout&gt;
      &lt;/ObservableScrollView&gt;
      &lt;Button /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>edit:</strong></p>
  
  <p><em>attached some scala code</em></p>
  
  <pre><code>observableScrollView.setScrollViewListener(new ScrollViewListener {
    override def onScrollChanged(scrollView: ObservableScrollView, x: Int, y: Int, oldx: Int, oldy: Int): Unit = {
  
      val scrollBottom = linearLayout.getHeight - observableScrollView.getHeight - 20
  
      if (y &gt;= scrollBottom) { // reached bottom
        composeButton.stateChange(STATE_SHOW)
      } else if (y &gt; 0 &amp;&amp; oldy &gt; 0 &amp;&amp; y &gt; oldy) { // scroll up
        composeButton.stateChange(STATE_HIDE)
      } else if (y &gt; 0 &amp;&amp; oldy &gt; 0 &amp;&amp; y &lt; oldy) { // scroll down
        composeButton.stateChange(STATE_SHOW)
      }
    }
  })
  </code></pre>
  
  <p>===== </p>
  
  <pre><code>val animationDuration: Int = 1000
  lazy val yStartPosition = getY // initialized on first access
  var currentState: ComposeButtonState = STATE_SHOW
  val animationQueue: AnimatorSet = new AnimatorSet()
  
  
  def animate(from:Float, to:Float) = {
    val anim = ObjectAnimator.ofFloat(this, "y", from, to)
    anim.setDuration(animationDuration)
    anim.setInterpolator(new OvershootInterpolator())
    animationQueue.play(anim)
    animationQueue.start()
  }
  
  def stateChange(state: ComposeButtonState) = {
    if (state != currentState) {
      currentState = state
      state match {
        case STATE_SHOW =&gt; animate(yStartPosition + yTranslateInitialValue, yStartPosition)
        case STATE_HIDE =&gt; animate(yStartPosition, yStartPosition + yTranslateInitialValue)
      }
    }
  }
  </code></pre>