How can I use marquee text in an android application?
-
Also, have a look at http://stackoverflow.com/questions/1827751/is-there-a-way-to-make-ellipsize-marquee-always-scroll – Felipe Oct 19 '11 at 17:59
-
Try alwaysMarqueeTextView stackoverflow.com/a/28806003/3496570 and forget about setSelection – Zar E Ahmer Mar 02 '15 at 09:11
-
**This answer can help you** [animate textView](https://stackoverflow.com/a/59223215/8748900) – abolfazl bazghandi Dec 07 '19 at 05:16
21 Answers
Here is an example:
public class TextViewMarquee extends Activity {
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) this.findViewById(R.id.mywidget);
tv.setSelected(true); // Set focus to the textview
}
}
The xml file with the textview:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/mywidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use marquee, with a long text" />
</RelativeLayout>

- 2,336
- 2
- 17
- 34

- 6,898
- 8
- 31
- 27
-
2
-
1This code worked for me - although I had to make sure the android:textColor was set otherwise I was sometimes getting very dark text on my already dark background. This is apparently different from the non-scrolling default in my setup which was white text. – JWGS Apr 16 '12 at 14:34
-
1This will not work, in case when your text will be short instead of this long line. – Robi Kumar Tomar Jun 17 '14 at 09:27
-
1
-
For those who uses Anko, equivalent of `marquee_forever` is `marqueeRepeatLimit = 0xFFFFFFFF.toInt()` – Miha_x64 May 16 '17 at 15:48
-
-
for me it's working fine for large text, but for small text like "hello", it's not moving. can someone help me – AMIT Nov 14 '19 at 07:00
-
1Combining ellipsedsize marquee with maxlines 1 can lead to crashes, replace maxlines with singleline=true – Gastón Saillén Apr 01 '20 at 15:51
android:ellipsize="marquee"
This only works when your TextView
has the focus.

- 29,392
- 25
- 90
- 143

- 9,789
- 2
- 36
- 53
-
He just did. You set `android:ellipsize="marquee"` on your `TextView`. It's all documented on developer.android.com by the way. – mxk Feb 02 '10 at 12:17
-
-
for me it's working fine for large text, but for small text like "hello", it's not moving. can someone help me – AMIT Nov 14 '19 at 07:00
TextView textView = (TextView) this.findViewById(R.id.textview_marquee);
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setText("General Information... general information... General Information");
textView.setSelected(true);
textView.setSingleLine(true);

- 19,513
- 22
- 110
- 155

- 3,531
- 6
- 34
- 45
Just put these params to your TextView - It works :D
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
And you also need to setSelected(true)
:
my_TextView.setSelected(true);
Greetings, Christopher

- 5,635
- 1
- 19
- 29

- 1,399
- 15
- 18
-
1Yes after putting my_TextView.setSelected(true),It's working Perffect.....Thanks.... – Vatsal Harde May 16 '17 at 04:56
-
-
Wow. Yet another "it's not a bug it's a feature". Now you have to subclass the TextView class just to apply these attributes, because just setting one property doesn't work. (faceplam) – TheRealChx101 Jun 23 '23 at 12:26
To get this to work, I had to use ALL three of the things (ellipsize, selected, and singleLine) mentioned already:
TextView tv = (TextView)findViewById(R.id.someTextView);
tv.setSelected(true);
tv.setEllipsize(TruncateAt.MARQUEE);
tv.setSingleLine(true):

- 101
- 1
- 2
Xml code
<TextView
android:id="@+id/txtTicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true"
android:gravity="center_horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:scrollHorizontally="true"
android:shadowColor="#FF0000"
android:shadowDx="1.5"
android:shadowDy="1.3"
android:shadowRadius="1.6"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold" >
</TextView>
Java
txtEventName.setSelected(true);
if text is small then add space before and after text
txtEventName.setText("\t \t \t \t \t \t"+eventName+"\t \t \t \t \t \t");

- 2,385
- 6
- 28
- 30
-
This helped me realise that I need the text to be longer than the width of the screen. – Leon Dec 03 '15 at 11:36
I found a Problem with marquee that it can't be used for short strings(As its function is only to Show Long strings).
I suggest Use Webview If you want to move short strings horizontally. Main_Activity.java Code:`
WebView webView;
webView = (WebView)findViewById(R.id.web);
String summary = "<html><FONT color='#fdb728' FACE='courier'><marquee behavior='scroll' direction='left' scrollamount=10>"
+ "Hello Droid" + "</marquee></FONT></html>";
webView.loadData(summary, "text/html", "utf-8"); // Set focus to the textview
`
main_activity.xml code:
<WebView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/web"
></WebView>

- 146
- 1
- 12

- 109
- 1
- 5
-
The most useful and flexible approach to implement a text ticker (running string). Thanks. – Dmytro Bilko Sep 04 '17 at 13:00
-
-
https://stackoverflow.com/a/43541663/15597511 ... for those whom this solution didnt work .... have a look at this .... similar but more effective – Daksh Rawal Jul 12 '22 at 06:08
In XML file, you need to add following additional attributes in a TextView to get a marquee like feature:
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
In MainActivity.java file, you can get the reference of this TextView by using findViewById() and you can set the following property to this TextView to make it appear like a marquee text:
setSelected(true);
That's all you need.

- 1,035
- 14
- 10
I have tried all of the above, but for me its didn't work. When I add
android:clickable="true"
then it's worked perfectly for me. I don't know why. But I am happy to work it.
Here is my full answer.
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"

- 1,751
- 1
- 14
- 19
Add Below Code in XML
<TextView
android:text="Shops NearBy textdf fsdgsdgsdg dsgtsgsdgsdgsg"
android:id="@+id/txtEventName"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:singleLine="true"/>
In Java add following Code:
TextView txtEventName=(TextView)findViewById(R.id.txtEventName);
txtEventName.setSelected(true);

- 107
- 10
Lots of answers correctly state that calling textView.setSelected(true)
is required. However, if preferred to do so just via XML, one option could be to make use of the Binding Adapters when working with Data Binding.
So, just create a new adapter similar to:
@BindingAdapter("app:autoStartMarquee")
fun setAutoStartMarquee(textView: TextView, autoStartMarquee: Boolean) {
textView.isSelected = autoStartMarquee
}
Then, you can simply use it in the XML as follows:
...
<TextView
...
android:ellipsize="marquee"
android:singleLine="true"
app:autoStartMarquee="@{true}"/>
...
No need to call it from code anymore.

- 1,129
- 9
- 26
As well as the XML settings identified by droidgren, my tests have shown that if the text you want to display is shorter than the width of the textview, then the marquee won't scroll at all. Possible solutions are to set the width of the view to a size smaller than the length of the text, or to concatenate the string to itself 2 or 3 times, with perhaps appropriate whitespace in-between so that the scrolling looks ok.

- 11,435
- 9
- 53
- 72
-
1I think you misunderstood the idea behind the marquee. It's not to make text move across the screen, it's to display text that is, well, longer than the width of the text view without having to shorten it. – Martin Marconcini Jul 12 '13 at 19:34
-
1You're right. I did misunderstand it. Thanks for clearing that up. – John J Smith Jul 13 '13 at 10:08
Use this to set Marque:
final TextView tx = (TextView) findViewById(R.id.textView1);
tx.setEllipsize(TruncateAt.MARQUEE);
tx.setSelected(true);
tx.setSingleLine(true);
tx.setText("Marquee needs only three things to make it run and these three things are mentioned above.");
You do not need to use "android:marqueeRepeatLimit="marquee_forever" into xml file. Marquee will work even without this.

- 118
- 1
- 10
You can use a TextView or your custom TextView. The latter is when the textview cannot get focus all the time.
First, you can use a TextView or a custom TextView as the scrolling text view in your layout .xml file like this:
<com.example.myapplication.CustomTextView
android:id="@+id/tvScrollingMessage"
android:text="@string/scrolling_message_main_wish_list"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/black"
android:gravity="center"
android:textColor="@color/white"
android:textSize="15dp"
android:freezesText="true"/>
NOTE: in the above code snippet com.example.myapplication is an example package name and should be replaced by your own package name.
Then in case of using CustomTextView, you should define the CustomTextView class:
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if(focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
public void onWindowFocusChanged(boolean focused) {
if(focused)
super.onWindowFocusChanged(focused);
}
@Override
public boolean isFocused() {
return true;
}
}
Hope it will be helpful to you. Cheers!

- 421
- 4
- 11
With the above answer, you cannot set the speed or have flexibility for customizing the text view functionality. To have your own scroll speed and flexibility to customize marquee properties, use the following:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:lines="1"
android:id="@+id/myTextView"
android:padding="4dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Simple application that shows how to use marquee, with a long text" />
Within your activity:
private void setTranslation() {
TranslateAnimation tanim = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 1.0f * screenWidth,
TranslateAnimation.ABSOLUTE, -1.0f * screenWidth,
TranslateAnimation.ABSOLUTE, 0.0f,
TranslateAnimation.ABSOLUTE, 0.0f);
tanim.setDuration(1000);//set the duration
tanim.setInterpolator(new LinearInterpolator());
tanim.setRepeatCount(Animation.INFINITE);
tanim.setRepeatMode(Animation.ABSOLUTE);
textView.startAnimation(tanim);
}
This will be equivalent to "end":
where = TruncateAt.END

- 83,810
- 28
- 209
- 234

- 1
This is my xml customTextView Object here you can use simply TextView to replace on Tag.
<com.wedoapps.crickethisabkitab.utils.view.montserrat.CustomTextView
android:id="@+id/lblRateUsPlayStore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_10sdp"
android:layout_marginBottom="@dimen/_10sdp"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:text="@string/please_rate_us_5_star_on_play_store"
android:textAllCaps="false"
android:textColor="@color/green"
android:textSize="@dimen/_25ssp"
android:textStyle="bold"
android:visibility="visible"
android:linksClickable="true"
android:autoLink="web|phone"/>
And here is My Java File code. i have set my html text on server just replace your text on textview object. i have put this code is marquee tag with clickable if any links on this textview to open mobile or webBrowser.
CustomTextView lblRateUsPlayStore = findViewById(R.id.lblRateUsPlayStore);
lblRateUsPlayStore.setMovementMethod(LinkMovementMethod.getInstance());
lblRateUsPlayStore.setText( Html.fromHtml(documentSnapshot.getString("DisplayText")));
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(lblRateUsPlayStore, 12, 20, 2, 1);
lblRateUsPlayStore.setEllipsize(TextUtils.TruncateAt.MARQUEE);
// Set marquee repeat limit (unlimited)
lblRateUsPlayStore.setMarqueeRepeatLimit(-1);
lblRateUsPlayStore.setHorizontallyScrolling(true);
lblRateUsPlayStore.setSelected(true);
lblRateUsPlayStore.setLinksClickable(true);
lblRateUsPlayStore.setFocusableInTouchMode(true);
lblRateUsPlayStore.setFocusable(true);

- 49
- 1
- 7
You can use
android:ellipsize="marquee"
with your textview.
But remember to put focus on the desired textview.

- 529
- 7
- 14
For setting Marquee programatically
TextView textView = (TextView) this.findViewById(R.id.textview_marquee);
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setMarqueeRepeatLimit(-1);
textView.setText("General Information... general information... General Information");
textView.setSelected(true);
textView.setSingleLine(true);

- 61
- 4
Special Thanks to David Roman , i changed his answer to kotlin
import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
class MarqueeTextView : AppCompatTextView {
constructor(context: Context?) : super(context!!) {}
constructor(context: Context?, attrs: AttributeSet?) : super(context!!, attrs) {}
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(
context!!,
attrs,
defStyle
) {
}
override fun onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?) {
if (focused) super.onFocusChanged(focused, direction, previouslyFocusedRect)
}
override fun onWindowFocusChanged(focused: Boolean) {
if (focused) super.onWindowFocusChanged(focused)
}
override fun isFocused(): Boolean {
return true
}
}

- 508
- 6
- 20
In Android (KOTLIN)
, the Marquee
effect for scrolling text can be achieved by using the TextView
widget and setting the android:ellipsize
and android:marqueeRepeatLimit
attributes in the layout XML file. Here's an example of how to create a marquee TextView in Kotlin
:
In your layout XML file (e.g.
activity_main.xml
), add a TextView with the desired text and marquee attributes:` <TextView
android:id="@+id/marqueeTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:text="This is a marquee text view example." android:focusable="true" android:focusableInTouchMode="true" android:scrollHorizontally="true"
/> `
In this example, we set android:singleLine
to true to ensure the text scrolls horizontally on a single line. The android:ellipsize
attribute is set to "marquee" to enable the marquee effect. The android:marqueeRepeatLimit
attribute is set to "marquee_forever" to make the marquee repeat indefinitely. The android:text attribute specifies the initial text to display.
Note: To make the marquee work, the TextView needs to have focus. Therefore, we set android:focusable
and android:focusableInTouchMode
to true to allow the TextView to gain focus.
- In your Kotlin code, you can optionally add the following lines to enable the marquee effect programmatically:
val marqueeTextView = findViewById<TextView>(R.id.marqueeTextView) marqueeTextView.isSelected = true
By setting isSelected to true, the TextView will start scrolling immediately when the view gains focus.
Make sure to replace R.id.marqueeTextView
with the actual ID of your TextView in your code. Adjust the layout attributes and text content according to your desired appearance and behavior.

- 9
- 3