How to reverse the direction of marquee of a TextView

I figured out a very simple and easy way to do this. I made a marquee effect to move in both directions depending on our selection. So, here is the trick:

I used a TextView inside a HorizontalScrollView. I controlled its scrolling in a programmatic way. I got length of text using:

scroll_pos = (int)myTextView.getLayout().getLineWidth(0);

Then I used Handler and called it recursively until I reach the scroll limit. In this handler I made my HorizontalScrollView to scroll to a certain position:

Handler hHandler = new Handler()
{
    @Override
    public void handleMessage(Message msg)
    {
        hScroll.scrollTo(scroll_pos, 0);
        scroll_pos--;
        if(scroll_pos >= 0)
            hHandler.sendEmptyMessage(0);
    }       
};

And here it goes, a smooth marquee from Left to Right. Cheers!

Leave a Comment