Current Android Release version:
Version Code: Pie
Version: 9
API level: 28

How to create a Scrolling Text (marquee) in android using TextView?

Below is the code to display scrolling text

XML:
<TextView
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="Sample Text"
               android:singleLine="true"
               android:ellipsize="marquee"
               android:marqueeRepeatLimit="marquee_forever"
               android:scrollHorizontally="true"
               android:id="@+id/text" />

In Java code, we have to set focus for text view to take scrolling effect.
TextView tv = (TextView) this.findViewById(R.id.text);
tv.setSelected(true); // Set focus to the textview

No comments:

Post a Comment