How to reverse the direction of marquee of a TextView

前端 未结 8 949
孤城傲影
孤城傲影 2020-11-30 05:16

I want to reverse the direction of marquee in the TextView. By default, the text moves from Right to Left, I want it to move from Left to Right. How can I do this?

8条回答
  •  感动是毒
    2020-11-30 05:38

    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!

提交回复
热议问题