2012-12-20 77 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" />