title: Android automatic horizontally scrolling TextView
body: <p>I am trying to implement a single-line text view that will scroll automatically. But I unfortunatly cannot get it to work. The AutoScrollTextView is declared inside a LinearLayout (width and height = fill_parent). The class basically uses a Handler that calls itself to scroll by a given amount. I have simplified the code to only show a text view that should be scrolling by 5 pixels every second.</p>
  
  <p>The log output is correct, the getScrollX() method returns the appropriate scrollX position. </p>
  
  <p>If I don't call <code>requestLayout()</code>, nothing gets drawn. <code>invalidate()</code> has no effect.</p>
  
  <p>Would anybody have a clue?</p>
  
  <pre><code>public class AutoScrollTextView extends TextView {
  
      public AutoScrollTextView(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
          setSingleLine();
          setEllipsize(null);
          setText("Single-line text view that scrolls automatically if the text is too long to fit in the widget");
      }
  
      // begin to scroll the text from the original position
      public void startScrolling() {
          scrollHandler.sendEmptyMessage(0);
      }
  
      private Handler scrollHandler = new Handler() {
          private static final int REFRESH_INTERVAL = 1000;
  
          public void handleMessage(Message msg) {
              scrollBy(5, 0);
              requestLayout();
              Log.debug("Scrolled to " + getScrollX() + " px");
              sendEmptyMessageDelayed(0, REFRESH_INTERVAL);
          }
      };
  }
  </code></pre>