title: Android ScrollView only scroll to bottom if you're already there
body: <p>I have a basic android app set up with a scroll view and text added to it dynamically.
  I want it to scroll to the bottom when text is added (which already happens) but I only want it to scroll to the bottom if you are already at the bottom, so if you're reading something it doesn't just scroll.
  Here's what I have so far.</p>
  
  <pre><code>private void AddText(final String msg){
      this.runOnUiThread(new Runnable() {
          public void run() {
              TextView log = (TextView) findViewById(R.id.chatlog);
              if(log.getText().equals("Loading...")){
                  log.setText(msg);
              }else{
                  ScrollView scroller = (ScrollView) findViewById(R.id.scroll_container);
                  //set current scroll position
                  int scroll_pos = scroller.getScrollY();
                  //scroll to bottom
                  scroller.fullScroll(ScrollView.FOCUS_DOWN);
                  //set bottom position
                  int scroll_bot = scroller.getScrollY();
                  //add the text
                  log.append("\r\n" + msg);
                  //if you weren't at the bottom
                  //scroll back to where you were.
                  //This isn't working, scroll bot is the same
                  //as scroll pos.
                  if(scroll_pos != scroll_bot){
                      scroller.scrollTo(0, scroll_pos);
                  }
                  //System.out.println("Pos: " + scroll_pos);
                  //System.out.println("Bot: " + scroll_bot);
              }
          }
      });
  }
  </code></pre>