Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Auto-scrolling text in TextView

I've created a series of tabs that have a fixed width of 100px. A tab contains an image with some text below it. If the text is too long to fit, I want it to automatically scroll. I only want one line. I tried the following but it did not work. I am using Android 2.3:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginRight="3dp"
    android:layout_marginTop="3dp"
    android:background="#ff737373"
    android:gravity="center"
    android:minWidth="64dp"
    android:orientation="vertical"
    android:padding="3dp" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:tag="tabImage" >
    </ImageView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:maxWidth="100px"
        android:tag="tabCaption"
        android:textColor="#ffd9d9d9"
        android:textSize="16sp" />

</LinearLayout>

Any idea why this does not work? I came across the solution from another posting and there the user indicated that it works.

like image 871
Johann Avatar asked Jun 25 '12 05:06

Johann


2 Answers

In your activity you have to add if you want to marquee on text

  TextView tv=(TextView)findViewById(R.id.textview1);
  tv.setSelected(true);
like image 151
Khan Avatar answered Nov 09 '22 14:11

Khan


You might want to try this:

https://github.com/kaeppler/ignition/blob/master/ignition-core/ignition-core-lib/src/com/github/ignition/core/widgets/ScrollingTextView.java

like image 44
Thomas Dignan Avatar answered Nov 09 '22 14:11

Thomas Dignan