Create Marquee Text in TextView

What is Marquee? Basically, Marquee is nothing but a scrolling text. When we have a long text to display in title, we mostly make it multi-line OR, the text wraps with three dots in a single line. But sometimes the multi-line also not works and it becomes a vertical wrap text which might confuse the user. And same also applicable for the single-line or horizontal text. So it will be better if we can show the full title or the full sentence, which will give proper meaning and also understandable by the user. And the trick will be by scrolling the whole text or sentence. Text scroll or marquee has done differently in different languages. As we are discussing for Android, we have to do the below things to make the text scroll in a TextView. Appling XML changes for TextView:

To make a marquee text, we have to use three main XML functionalities inside the TextView and these are

  • android:layout_width=”match_parent”
  • android:singleLine=”true”
  • android:ellipsize=”marquee”
I just pasted one image of one of my XML for marquee TextView below to make it simple.
marquee text color change

marquee text color change

  Appling Code changes for TextView: Now, we have to do a very small change in our code (i.e in Java class) to make it work. The last change we have to do is, just making the selectable to true for the TextView by adding the code like textview.setSelected(true). Just check the image below.
Appling Code changes for TextView

Appling Code changes for TextView

And, we are ready to make our TextView scrollable now. Make sure the text is crossing the width limit for marquee. You can add some left or right margins if you want for a smooth scroll. Mobile Phone Reviews, News Specifications

      Compare items
      • Total (0)