Шах Шах - 5 months ago 71
Android Question

Run TextView marquee after some time

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?

Answer

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);
                mTVTitle.invalidate();
            }
        }, 1000);