6

Marquee not working for my TextView Please check below code

XML Code for TextView

                          <TextView
                            android:id="@+id/mtextcash"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="30dp"
                            android:ellipsize="marquee"
                            android:fadingEdge="horizontal"
                            android:gravity="center"
                            android:marqueeRepeatLimit="marquee_forever"
                            android:maxLength="5"
                            android:scrollHorizontally="true"
                            android:scrollbars="horizontal"
                            android:singleLine="true"
                            android:text="Simple application that shows how to use marquee, with a long text"
                            android:textColor="@color/white"
                            android:textColorHint="@color/white"
                            android:textSize="25dp" />

In Activity OnCreate

TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash);
inputAvailableCash.setSelected(true);

Thanks in Advance

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
Yogesh Borhade
  • 694
  • 1
  • 10
  • 24
  • The issue is with your android:layout_width value which is wrap_content. check readyandroid answer. – Ready Android Jan 12 '17 at 05:52
  • 1
    Possible duplicate of http://stackoverflow.com/questions/10458844/textview-marquee-doesnt-work?rq=1 or http://stackoverflow.com/questions/24165143/textview-with-marquee-is-not-working?rq=1 – Ranjan Jan 12 '17 at 05:55

7 Answers7

8

Since the text is very long and and your code will only work if you write the text in single line. Either add

 android:singleline="true" 

in xml or change your java code to.

  TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash);
        inputAvailableCash.setSelected(true);
         inputAvailableCash.setSingleLine(true);

This will surely work for you.

Vipin NU
  • 301
  • 2
  • 16
  • 1
    I had `maxLines="1"` but it turned out it's not enough. `singleline="true" ` made it work! 10x. – WindRider Oct 21 '17 at 15:45
  • I realised that the marquee effect only started its animation when I touched it, so I looked and found your answer. In Kotlin is `inputAvailableCash.isSelected = true`. Is that possible by typing it in the layout/XML? – joninx Jun 10 '22 at 06:57
4

Once try by putting these params to your TextView - It works

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);
Varma460
  • 497
  • 1
  • 4
  • 13
3

The minimum code to run marquee on TextView is

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

also do not forget to set selected as below

textview.setSelected(true);
Reza Abedi
  • 419
  • 4
  • 16
1

add this attribute in the xml file

android:focusable="true"    
android:focusableInTouchMode="true" 
Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
1

For marquee effect width should be "match_parent" or static(like 200dp...etc) always. And programatically make it setSelected true as you already done then just make it's width as match_parent in xml it will work.

Edited xml:

                     <TextView
                        android:id="@+id/mtextcash"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="30dp"
                        android:ellipsize="marquee"
                        android:fadingEdge="horizontal"
                        android:gravity="center"
                        android:marqueeRepeatLimit="marquee_forever"
                        android:maxLength="5"
                        android:scrollHorizontally="true"
                        android:scrollbars="horizontal"
                        android:singleLine="true"
                        android:text="Simple application that shows how to use marquee, with a long text"
                        android:textColor="@color/white"
                        android:textColorHint="@color/white"
                        android:textSize="25dp" />

If by doing match_parent it will effect at your design then you have to manage for it by fixing it's width or with some other way.

As per your xml code you are using android:maxLength="5" means only 5 character will be entered so you can fix it's width by 50dp or any other static size.

Ready Android
  • 3,529
  • 2
  • 26
  • 40
1

Hey check this code but marquee working when your text size i.e length is longer.its working at my side.:)

 <TextView
        android:id="@+id/mywidget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:singleLine="true"
        android:textColor="#2086CA"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
        android:textAppearance="?android:attr/textAppearanceSmall" />

Hope this helps.:)

Pratik Gondil
  • 689
  • 1
  • 6
  • 17
0
<TextView android:id="@+id/mtextcash"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="30dp"
                   android:ellipsize="marquee"
                   android:gravity="center"
                   android:marqueeRepeatLimit="marquee_forever"
                   android:scrollHorizontally="true"
                   android:singleLine="true"
                   android:text="Simple application that shows how to use marquee, with a long text"
                   android:textColor="@color/white"
                   android:textColorHint="@color/white"
                   android:textSize="25dp" />
Chetan Patel
  • 180
  • 8