Moving text in textView android

<TextView
        android:id="@+id/YOURID"
        android:layout_width="15dp"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        />

This will help it to scroll until it is focused


an example -

in the XML :

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:textColor="#ff4500"
        android:text="this is a very long piece of text that will move" />
</RelativeLayout>

in Java:

        tv = (TextView) this.findViewById(R.id.tv);  
        tv.setSelected(true);  // Set focus to the textview

You should use android:ellipsize="marquee".

EDIT: you can use textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);

Tags:

Android