问题描述
我想在 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:
我在 HorizontalScrollView 中使用了 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);
然后我使用 Handler 并递归调用它,直到达到滚动限制.在这个处理程序中,我让我的 HorizontalScrollView 滚动到某个位置:
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 的选取框方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!