2

How to make a Marquee TextView wait for a specific time until it starts to scroll horizontally? Because when I open an Activity it starts straight to scroll. So you have to wait until its back on startposition to read it.

XxGoliathusxX
  • 922
  • 13
  • 34

4 Answers4

4

In the XML I simply added TextView like this:

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!, Hello World!, Hello World!, Hello World!, Hello World!, Hello World!, Hello World!, Hello World!"
    android:ellipsize="marquee"
    android:singleLine="true"
    android:marqueeRepeatLimit="marquee_forever"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:freezesText="true"
    android:maxLines="1"
    android:scrollbars="none" />

Then in code (in Activity, but can be anywhere):

TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textView = (TextView) findViewById(R.id.textView);
    textView.setSingleLine(false);
    textView.setMaxLines(1);
}

@Override
protected void onResume() {
    super.onResume();

    textView.postDelayed(new Runnable() {
        @Override
        public void run() {
            textView.setSingleLine(true);
        }
    }, 3000);
}
Dimitar
  • 4,402
  • 4
  • 31
  • 47
zombie
  • 5,069
  • 3
  • 25
  • 54
1

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

tv.setSelected(true);

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

tv.postDelayed(new Runnable() {
            @Override
            public void run() {
                tv.setSelected(true);          
            }
        }, 1000);

this will delay it

Community
  • 1
  • 1
0
<TextView
             android:id="@+id/testing"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:ellipsize="marquee"
             android:focusable="true"
             android:focusableInTouchMode="true"
             android:singleLine="true"
             android:text="Some veryyyyy long text with all the characters that cannot fit in screen, it so sad :( that I will not scroll"
             android:layout_below="@id/toolbar"
/>

Then, in activity just set using setSelection to true. I already tested it and its working

testing.postDelayed(new Runnable() {
            @Override
            public void run() {
                testing.setMaxLines(1);
                testing.setEllipsize(TextUtils.TruncateAt.MARQUEE);
                testing.setMarqueeRepeatLimit(10000);
                testing.setSelected(true);
            }
        }, 3000);
ZeroOne
  • 8,996
  • 4
  • 27
  • 45
-1

All you need to do is delay the focus of textview so that it starts it marquee after a certain period of time. The following code starts rolling the marquee after 2 seconds.

yourTextview.postDelayed(new Runnable() {
            @Override
            public void run() {
                yourTextview.setSelected(true);          
            }
        }, 2000);

P.S : You first need to post what you have tried so far.

San
  • 2,078
  • 1
  • 24
  • 42