在android中具有特定时间间隔的文本视图的垂直自动滚动文本

时间:2012-10-02 06:53:38

标签: android timer scroll textview scrollview

我是android的初学者。在我的应用程序中,我的textview有多行文本,它可能有15-20行。我希望在该textview中垂直自动滚动文本。那么解决方案是什么呢?

这是我的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);

1 个答案:

答案 0 :(得分:0)

您实际上不需要使用ScrollView。

只需设置

即可
android:maxLines = "AN_INTEGER_NUMBER"

android:scrollbars = "vertical"

布局的xml文件中TextView的属性。

然后使用:

yourTextView.setMovementMethod(new ScrollingMovementMethod())

代码。