10

I've been looking around for quite some time now, and I can't get a straight answer for my question.

It's quite simple: How can I get a nice scrolling text just like the long app names in the Market when you select an application?

mariusgreve
  • 2,621
  • 6
  • 23
  • 31

5 Answers5

17

I've figured it out by myself.

android:ellipsize="marquee"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
Matt
  • 74,352
  • 26
  • 153
  • 180
mariusgreve
  • 2,621
  • 6
  • 23
  • 31
  • Ah, your TextView is in a ListView ! Btw, don't work with focusableInTouchMode until you fully understand it and mark the question as answered. – fedj Oct 06 '10 at 09:46
  • No, it's in a `RelativeLayout` that is used as a custom title... I can't mark it as answered until tomorrow because of my lack of reputation – mariusgreve Oct 06 '10 at 11:21
8

Make a translate animation in your anim folder like:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="12000"
    android:fromXDelta="100"
    android:interpolator="@android:anim/linear_interpolator"
    android:repeatCount="infinite"
    android:repeatMode="restart"
    android:toXDelta="-100" />

And then to your textview like:

yourtextview.startAnimation((Animation)AnimationUtils.loadAnimation(Context,R.anim.youranim_xml));

Hope this might help you.

Edit:

Try this:

<TextView 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:lines="1"
android:marqueeRepeatLimit="marquee_forever"
android:padding="4dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Simple application that shows how to use marquee, with a long text" />
IronBlossom
  • 3,898
  • 3
  • 35
  • 42
  • I like this approach a lot. – maddesa Jan 24 '14 at 17:29
  • Animation is working but how to remove ... from the end of the textview and increase the size of textview to its content – Hemant Shori Apr 09 '15 at 07:28
  • @Hemant `yourtextview.clearAnimation()` will stop the animation. You can do textview ui staffs after that. – IronBlossom Apr 09 '15 at 07:30
  • @IronBlossom Man .actually animation is clipping rest of the text its like this `Today's news this that die injured ...` the rest of the text is clipped I want to increase the size of TextView cause animation is animating just this much part not the whole text – Hemant Shori Apr 09 '15 at 07:39
  • @Hemant Set your textview ellipsize to `none` and `layout_width=wrap_content` – IronBlossom Apr 09 '15 at 07:41
  • @IronBlossom I have tried this but still size remains same. it is clipping the textview width .Also i am using singleline="true" – Hemant Shori Apr 09 '15 at 07:45
  • 1
    hey its Done i have Put my Text View in `HorizontalScrollView`. how to increase the speed of animation' – Hemant Shori Apr 09 '15 at 07:56
6

the decision which works for me:

textView.setSelected(true); 
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setSingleLine(true);

without focusable's parameters

meda
  • 45,103
  • 14
  • 92
  • 122
Elena
  • 503
  • 1
  • 5
  • 10
0
android:ellipsize="marquee"
fedj
  • 3,452
  • 1
  • 22
  • 21
0
  1. Use a normal TextView with the following config:

    android:text="your text here"
    android:id="@+id/MarqueeText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:scrollHorizontally="true"
    android:focusable="true"
    android:focusableInTouchMode="true" />
    

The problem with this is that you cannot adjust the speed of the scrolling text.

  1. Enclose a TextView within a ScrollView:

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
            <TextView
            android:id="@+id/myTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Your Text here" >
        </TextView>
    </ScrollView>
  1. Create custom class and follow this thread
Community
  • 1
  • 1
Jaydev
  • 1,794
  • 20
  • 37