2

How can I run a text marquee in the TextView with delay before start?
At this moment I use the next code to start:

mTVTitle.postDelayed(new Runnable() {
    @Override
        public void run() {
            mTVTitle.setFocusableInTouchMode(true);
            mTVTitle.invalidate();
        }
    }, 1000);

TextView xml:

<TextView
    android:id="@+id/tvTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:focusable="true"
    android:marqueeRepeatLimit="2"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:textAppearance="?attr/titleTextAppearance"
    android:textColor="@color/white"/>

But it doesn't work although if I set this property in xml then all right. How to fix it to I can start a marquee programmatically?

Denis Sologub
  • 7,277
  • 11
  • 56
  • 123

1 Answers1

2

As mentioned here in order to activate textview marquee you have to add this :

mTVTitle.setSelected(true);

As you want to start the marquee with a delay you have to put this inside your run() like this

mTVTitle.postDelayed(new Runnable() {
            @Override
            public void run() {
                mTVTitle.setSelected(true);          
            }
        }, 1000);
Community
  • 1
  • 1
Kingston
  • 474
  • 5
  • 14
  • Thanks! Although, I don't understand why in the code we use an another property?. And I tested... It's unnecessary to call `invalidate()` – Denis Sologub Jul 04 '16 at 20:42
  • 1
    Yes it wont be necessary to call invalidate() . But if you would like to convert normal textview into a textview with marquee enabled programatically you might have to call invalidate(). Edited my answer as we are not doing any such changes. – Kingston Jul 05 '16 at 06:40