14

android中的Marquee是否有任何工作示例?我浏览了一些网站,但这些例子不起作用。

感谢您的回答.. 但是以下代码无论如何都不起作用。我使用的是安卓 2.2。

       <TextView    
             android:singleLine="true"  
             android:ellipsize="marquee" 
             android:marqueeRepeatLimit ="marquee_forever"
             android:text="Marquee.."/> 
4

5 回答 5

32

通过 XML 很容易做到。使用以下设置:

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

如果您的TextView 在RelativeLayout 内,则宽度或高度必须是静态的(即32dp)。如果您需要动态,请将 TextView 放在 RelativeLayout 内的另一个视图中。

在 onCreate() 中,您需要选择 TextView:

myTextView.setSelected(true);
于 2011-03-23T04:20:39.147 回答
2

你忘记在java中这样做了..

tv.setSelected(true);

和 xml 将是

android:scrollHorizontally="true"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="false"
android:marqueeRepeatLimit="marquee_forever"
于 2013-03-05T16:28:24.690 回答
2

您缺少的代码行是:

    android:focusable="true"
    android:focusableInTouchMode="true"
    android:singleLine="true"

在文本字段中尝试此文本,因为它是一个长文本。

android:text="This is a very long text which is not fitting in the screen so it needs to be marqueed."

在此处检查我的完整代码和分步过程

于 2012-09-12T17:45:09.953 回答
0

您可以设置ellipsize=marqueemarqueeRepeatLimit属性:

例如:我已经为 TextView 设置了:

 android:ellipsize="marquee"
 android:marqueeRepeatLimit ="marquee_forever"

您可以参考此 SO Question 以获得最佳信息:Is there a way to make ellipsize="marquee" always scroll?

于 2010-12-03T10:27:44.920 回答
0

使用 android:ellipsize="marquee"

 <TextView  
    android:id="@+id/secondLine"   
    android:singleLine="true"
    android:ellipsize="marquee"
    android:text="Simple application marquee sample..."/>

Keeo Text 大到足以让它执行选取框效果。

于 2010-12-03T10:27:19.140 回答