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
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.
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.
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.
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.
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.
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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With