Android automatic horizontally scrolling TextView Android automatic horizontally scrolling TextView android android

Android automatic horizontally scrolling TextView


If you don't need to sub-class the TextView, you can try this in your layout file:

    <TextView        android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget"         android:singleLine="true"        android:ellipsize="marquee"        android:marqueeRepeatLimit ="marquee_forever"        android:focusable="true"        android:focusableInTouchMode="true"         android:scrollHorizontally="true"        android:layout_width="wrap_content"         android:layout_height="wrap_content"/>

Also, in your code use the following:

findViewById(R.id.serviceColorCode).setSelected(true);

[Answer edited based on comments]


After these xml code as answered by @rajat

<TextView        android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget"         android:singleLine="true"         android:ellipsize="marquee"        android:marqueeRepeatLimit ="marquee_forever"        android:focusable="true"        android:focusableInTouchMode="true"         android:scrollHorizontally="true"        android:layout_width="wrap_content"         android:layout_height="wrap_content"/>

We need to set

TextView tv=(TextView)findViewById(R.id.textview1);  tv.setSelected(true); 

which finally made mine work


My solution works:

<TextView     android:id="@+id/titolotxt"     android:layout_width="..."     android:layout_height="..."     android:ellipsize="marquee"     android:gravity="left"     android:marqueeRepeatLimit="marquee_forever"     android:singleLine="true"     android:text="@string/titolo"/>

And the TextView have to be setted selected: textView.setSelected(true); by code in onCreate for example.