在我的应用程序中,我必须实现一个自动滚动的 TextView ,我引用了 this链接。
现在我有一个滚动的 tetxview。但根据我的要求,我有一个字符串数组(我已经解析并且我有一些字符串)..考虑数组可能是
string[] array=new string{"fgsdfd","gdfghdjhsd","gdfjhsgfhds"};
现在我希望这个数组显示在那个 TextView 中(它将自动滚动)。
我想要这样:
fgsdfd gdfghdjhsd gdfjhsgfhds------------------>this will scroll automatically
这是我的 TextView (滚动):
<TextView
android:text="Really Long Scrolling Text Goes Here.... ..... ............ .... ...."
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:id="@+id/TextView03"
android:padding="5dip"
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_height="wrap_content" />
如何将字符串数组设置为 tetxview..请帮助我。
最佳答案
您可以通过 StringBuilder
将所有字符串合并为一个字符串并将其应用于 TextView
。
我已经通过包装 textview(可能还有一些其他 View )实现了我自己的带有滚动的 TextView
private Runnable scrollRight = new Runnable()
{
@Override
public void run()
{
// can control scrolling speed in on tick
topScroll.smoothScrollBy(1, 0);
}
};
在我调用的新线程中:
while (!interruptScroll){
try{
Thread.sleep(50); // control ticking speed
}
catch (InterruptedException e){
e.printStackTrace();
}
topScroll.post(scrollRight);
}
并通过手动滚动 scrollView 我中断了滚动(这样的自动滚动而不被用户中断)。
关于android - 在android中滚动Textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13966782/