如何扭转一个TextView的选取框的方向 [英] How to reverse the direction of marquee of a TextView

查看:150
本文介绍了如何扭转一个TextView的选取框的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要扭转选取框在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!

这篇关于如何扭转一个TextView的选取框的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆