2012-12-20 75 views
5

在我的应用程序中,我必须实现自动滚动文本视图,我提到了this链接。在android中滚动Textview

现在我有一个根据我的要求滚动tetxview.But是,我有一个字符串数组(我已经解析了,我有一些字符串)..考虑该阵列可以

string[] array=new string{"fgsdfd","gdfghdjhsd","gdfjhsgfhds"}; 

现在我想这个数组将显示在该文本视图中(它将自动滚动)。

我想是这样的:

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..Please帮助我。

回答

1

尝试使用StringBuilder。

String[] array = { "fgsdfd", "gdfghdjhsd", "gdfjhsgfhds" }; 
StringBuilder sb = new StringBuilder(); 

for (int i = 0; i < array.length; i++) { 
    sb.append(array[i]); 
} 
txtView.setText(sb.toString()); 
+0

感谢您的回答.. – Subburaj

3

您可以通过StringBuilder合并一个字符串中的所有字符串,并将其应用于TextView

我已经通过包装的TextView实现我自己的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); 
} 

,并通过手动滚动了滚动我中断滚动(这种自动滚动而不被用户中断)。

+0

感谢答案.. – Subburaj

+0

而且顺便说一句 - 实现自动滚动使用滚动型,smoothScrollBy和线程\定时器。 – dilix

+0

k ...感谢dilix ...你可以做更多的favour ..在上面的代码滚动发生非常缓慢..我希望他们滚动一点点快..我可以在上面的代码完成.. – Subburaj

0

试试这个,

<TextView 
android:text="Really Long Scrolling Text Goes Here.... ..... ............ .... ...." 
android:singleLine="true" 
android:ellipsize="marquee" 
android:marqueeRepeatLimit="marquee_forever" 
android:scrollbars="horizontal" 
android:id="@+id/TextView03" 
android:padding="5dip" 
android:layout_width="wrap_content" 
android:textColor="#000000" 
android:layout_height="wrap_content" />