Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextView Marquee not working

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

like image 907
Yogesh Borhade Avatar asked Jan 12 '17 05:01

Yogesh Borhade


People also ask

How to add a marquee to a text on Android?

Here we have used android:ellipsize=”marquee” to add a marquee to our text and android:singleLine=”true” so that our text will show only in one line.

How to display text on the screen using Android Studio?

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that you have to select Java as the programming language. Navigate to the app > res > layout > activity_main.xml and add the below code to that file. TextView is used here to add the text which we want to display on the screen.

How to dynamically set text in a textview?

TL;DR: If you are dynamically setting the text of the TextView, try setting the required "marquee" properties in code instead of in the layout xml file. Longer version: In my case, I had a GridView with an adapter and a TextView in each item.

Why doesn't the ellipsis work in the textview?

The TextView needs a specific width for the ellipsis to work and won't work with "wrap_content". Thanks for the reply chirsbjr, but I had already tried the change you suggested without success. Indeed the wrap_content attribute works well for the TextView.


3 Answers

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.

like image 167
Vipin NU Avatar answered Sep 27 '22 23:09

Vipin NU


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);
like image 36
Varma460 Avatar answered Sep 27 '22 23:09

Varma460


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);
like image 39
Reza Abedi Avatar answered Sep 27 '22 21:09

Reza Abedi