Android Marquee [duplicate]

吃可爱长大的小学妹 提交于 2019-11-26 18:26:45

问题


This question already has an answer here:

  • Marquee text in Android 19 answers

Is there any working example for Marquee in android? I went through some sites, but that examples are not working.

Thank you for the answers.. But the following code is not working anyway. I am using Android 2.2.

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

回答1:


it's easy to do via XML. Use the following settings:

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

If your TextView is within a RelativeLayout, the width or height will have to be static (i.e. 32dp). If you need dynamic, place the TextView in another View within the RelativeLayout.

In onCreate(), you need to make the TextView selected:

myTextView.setSelected(true);



回答2:


The code lines you were missing are :

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

In the text field try this text as it is a long text.

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

Check my complete code and step by step process here




回答3:


You have forgotten to do this in java..

tv.setSelected(true);

and the xml will be

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



回答4:


Use android:ellipsize="marquee"

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

Keeo Text to large enough to let it perform marquee effect..




回答5:


You can set ellipsize=marquee and marqueeRepeatLimit attribute:

For example: I have set for the TextView:

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

You can refer this SO Question for the best information: Is there a way to make ellipsize="marquee" always scroll?



来源:https://stackoverflow.com/questions/4344349/android-marquee

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!