Marquee using maxLines
Asked Answered
C

2

5

How can I have a marquee using MaxLines instead of SingleLine ?

This is my TextView :

<TextView
    android:text="bla bla bla bla bla bla"
    android:id="@+id/MarqueeText" 
    android:layout_width="30dp"
    android:layout_height="wrap_content" 
    android:singleLine="true"
    android:ellipsize="marquee" 
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:freezesText="true">

After in my code.java I setSelected my TextView :

TextView txtView=(TextView) findViewById(R.id.MarqueeText);
txtView.setSelected(true);

The problem is android:singleLine is deprecated so I have to use android:maxLines instead but the marquee don't work with it.

Colligan answered 19/2, 2017 at 18:34 Comment(0)
Z
1

You can try using this :

android:maxLength = "10"

OR

After setting android:maxLines="1", you have to set your inputType too. So, set your android:inputType="text" and that should do the trick.

Zamir answered 19/2, 2017 at 18:43 Comment(2)
we can't set inputType for a TextViewLeyva
Why not? see this link developer.android.com/reference/android/widget/TextView.htmlZamir
H
4

In XML

<TextView
    android:text="11111111111111111111111111111111111111111111111111111111111111"
    android:id="@+id/text_marquee"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="1"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    />

In Java

((TextView)findViewById(R.id.text_marquee)).setHorizontallyScrolling(true);
((TextView)findViewById(R.id.text_marquee)).setSelected(true);
Holothurian answered 22/9, 2017 at 8:48 Comment(0)
Z
1

You can try using this :

android:maxLength = "10"

OR

After setting android:maxLines="1", you have to set your inputType too. So, set your android:inputType="text" and that should do the trick.

Zamir answered 19/2, 2017 at 18:43 Comment(2)
we can't set inputType for a TextViewLeyva
Why not? see this link developer.android.com/reference/android/widget/TextView.htmlZamir

© 2022 - 2024 — McMap. All rights reserved.