如何扭转一个TextView的选取框的方向方向、TextView

由网友(愛到陌路)分享简介:我要扭转选取框在TextView中的方向。默认情况下,由右至左的文字动作,我希望它从左移动到右。我怎样才能做到这一点?I want to reverse the direction of marquee in the TextView. By default, the text moves from Right to...

我要扭转选取框在TextView中的方向。默认情况下,由右至左的文字动作,我希望它从左移动到右。我怎样才能做到这一点?

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?

推荐答案

我想出了一个非常简单和容易的方法来做到这一点。我做了一个字幕效果,在这取决于我们选择两个方向移动。所以,这里有个技巧:

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:

我用了一个Horizo​​ntalScrollView里面一个TextView。我以编程的方式来控制其滚动。我使用了文本的长度:

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);

然后我用处理程序,并把它称为递归,直到我到了滚动的限制。在此处理我做了我的Horizo​​ntalScrollView滚动到一定位置:

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!

阅读全文

相关推荐

最新文章