2013-01-11 161 views
2

我明白,这可能是重复的,但我还没有找到答案.....呢!平滑水平滚动文本

我该如何在我的Android应用程序中制作水平滚动文字平滑?我希望文本能像电视新闻上的股票一样滚动。当滚动完成时我还需要回调,因此我可以设置新的文本进行滚动。

这样做的最好方法是什么?

谢谢!

+0

你有什么样的设计..然后更新与什么样的滚动你真的需要 – Janmejoy

回答

0

对于手动滚动

<HorizontalScrollView android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView android:layout_width="40dp" 
    android:layout_height="wrap_content" 
    android:scrollHorizontally="true" 
    android:text="Horizontal scroll view is working"/> 

</HorizontalScrollView> 

对于自动滚动

<TextView 
    android:text="Single-line text view that scrolls automatically if the text is too long to fit " 
    android:singleLine="true" 
    android:ellipsize="marquee" 
    android:marqueeRepeatLimit ="marquee_forever" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:scrollHorizontally="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
+1

我想他希望它自动滚动。 – dmon

+0

是的,我希望它自动滚动。 –

+0

我写了自动滚动和手动滚动的代码。 –

0

很好的问题。

首先要做到这一点,地方下面的代码在你的layout文件TextView

android:ellipsize="marquee" 
android:focusable="false" 
android:marqueeRepeatLimit="marquee_forever" 
android:scrollHorizontally="true" 
android:singleLine="true" 

然后写下面的代码文件中的代码,

TextView txt = (TextView) findViewById(R.id.textView); 
txt.setSelected(true); 

你必须给setSelected(true)做出的TextView自动滚动。

谢谢。