2012-12-20 17 views
5

私のアプリケーションでは、私は自動的にスクロールするtextviewを実装する必要があります、私は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

すべての文字列を1つの文字列でStringBuilderでマージし、TextViewに適用できます。

私は

private Runnable scrollRight = new Runnable() 
{ 

    @Override 
    public void run() 
    { 
        // can control scrolling speed in on tick 
     topScroll.smoothScrollBy(1, 0); 
    } 
}; 

と私は呼び出す新しいスレッドでのTextView(そしておそらくいくつかの他のビュー)をラップすることにより、スクロールして自分のTextViewを実装しました:

while (!interruptScroll){ 
    try{ 
     Thread.sleep(50); // control ticking speed 
    } 
    catch (InterruptedException e){ 
     e.printStackTrace(); 
    } 
    topScroll.post(scrollRight); 
} 

と手動scrollViewをスクロールすることにより、私はスクロールを中断します(ユーザーが中断しないような自動スクロール)。

+0

答え.. – Subburaj

+0

ためのおかげで、 - タイマー\自動スクロールの使用ScrollView、smoothScrollByとスレッドを実装します。 – dilix

+0

k ...おかげでディリックス... 1つ以上の好きなことをすることができます..上記のコードでは、スクロールは非常にゆっくりと起こっています..私はそれらを少し速くスクロールしたい..どのように私は上記のコードで達成することができます.. – 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" /> 
関連する問題