2012-10-02 77 views
0

我在android中是begginer。在我的應用程序中,我有textview有多行文本,它可能有15-20行。我想在該文本視圖中垂直自動滾動文本。那麼解決方案是什麼?垂直自動滾動textview與特定時間間隔的文本android

這裏是我的XML代碼:

<LinearLayout 
    android:id="@+id/Thumbnail" 
    android:layout_width="fill_parent" 
    android:layout_height="200dp" 
    android:paddingTop="10dp" 
    android:paddingBottom="10dp" 
    android:gravity="center" 
    android:background="@drawable/imgres"> 
    <ScrollView  
     android:id="@+id/sv"  
     android:layout_width="fill_parent"  
     android:layout_height="fill_parent"  
     android:fillViewport="true" > 

    <TextView 
    android:id="@+id/tv" 
    android:layout_width="fill_parent" 
    android:layout_height="200dp" 
    android:background="#80000000" 
    android:width="200dp" 
    android:textStyle="bold" 
    android:textColor="#ffffff" 
    android:gravity="center" 
    android:layout_alignParentTop="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:scrollbars = "vertical" 
    android:maxLines="10" 
    />  
    </ScrollView> 
</LinearLayout> 

在功能我一直在使用下面的代碼設置我的TextView的文本:

tv.setText(textArray); 
+0

你檢查這http://stackoverflow.com/questions/11184054/android-auto-scrolling-text-in-textview –

+0

我已經檢查[鏈接](http://stackoverflow.com/questions/11184054/ android-auto-scrolling-text-in-textview)。但我想要垂直滾動。你有任何的飲料? – zanky

回答

1

你不需要實際使用滾動型。

只需設置你的TextView的

android:maxLines = "AN_INTEGER_NUMBER" 

android:scrollbars = "vertical" 

屬性在佈局的XML文件。

然後使用:

yourTextView.setMovementMethod(new ScrollingMovementMethod()) 

在你的代碼。

+0

是的,這段代碼運行良好。但我想實現具有特定時間間隔的自動滾動。 – zanky