2

I've tried all, I can think of to get this marquee effect to work. Here is my xml:

<TextView android:id="@+id/curPlaying"
    android:layout_width="320dp"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:ellipsize="marquee"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:marqueeRepeatLimit ="marquee_forever"
    android:focusable="true"
    android:focusableInTouchMode="true" 
    android:textColor="#83A602"
    android:textSize="20dp"
    android:text="Nothing Loaded" />

And I'm setting it as selected in code. The only thing why I think it might not be working is the text is getting modified by the code at relatively frequent intervals.

Help?

Maveňツ
  • 1
  • 12
  • 50
  • 89
Mitchell
  • 929
  • 2
  • 11
  • 34
  • possible duplicate of [Is there a way to make ellipsize="marquee" always scroll?](http://stackoverflow.com/questions/1827751/is-there-a-way-to-make-ellipsize-marquee-always-scroll) – Vladimir Ivanov May 31 '12 at 19:17

4 Answers4

1

Hi Please try below code it is working fine for me...

<TextView
            android:id="@+id/mywidget"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:lines="1"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:text="Simple application that shows how to use marquee, with a long text"
            android:textColor="#ff4500" />

TextView tv = (TextView) this.findViewById(R.id.mywidget);
        tv.setSelected(true); // Set focus to the textview

It is working on My Samsung Galaxy ACE Phone.

Nikhil
  • 16,194
  • 20
  • 64
  • 81
0

You could checkout Marquee feature of TextView in Android 1.1R1, that explains certains ways where marquee can have a problem in getting work. ScrollTextView - scrolling TextView for Android might be a good option.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
0

I post because there are no accepted answers.... and helps future visitors who come to Stack Overflow for answers.

  public class AlwaysMarqueeTextView extends TextView {

  public AlwaysMarqueeTextView(Context context) {
  super(context);
  }

  public AlwaysMarqueeTextView(Context context, AttributeSet attrs) {
  super(context, attrs);
  }

  public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  }

  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
  super(context, attrs, defStyleAttr, defStyleRes);
  }

  @Override
  public boolean isFocused() {
  return true;
  }
  }

activity.xml

<ivar.kov.util.textViewUtil.AlwaysMarqueeTextView
  android:id="@+id/artist_tv2"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:ellipsize="marquee"
  android:focusable="true"
  android:focusableInTouchMode="true"
  android:marqueeRepeatLimit="marquee_forever"
  android:scrollHorizontally="true"
  android:singleLine="true"
  android:text="@string/appbar_scrolling_view_behavior"/>
sivaBE35
  • 1,876
  • 18
  • 23
0

If TextView fill whole width you need to add these lines of code

<TextView
    .
    .
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    />

also do not forget to set selected for TexrtView as below

textview.setSelected(true);

and If TextView does not fill width the only thing is to call this method and pass TextView to it.

    fun addMarquee(textView: TextView) {
    textView.viewTreeObserver.addOnGlobalLayoutListener(object :
        ViewTreeObserver.OnGlobalLayoutListener {
        override fun onGlobalLayout() {
            val pixels = textView.measuredWidth - 1
            val params = textView.layoutParams
            params.width = pixels
            textView.layoutParams = params
            textView.isSelected = true
            textView.ellipsize = TextUtils.TruncateAt.MARQUEE
            textView.isSingleLine = true
            textView.marqueeRepeatLimit = -1
            textView.viewTreeObserver.removeOnGlobalLayoutListener(this)
        }
    })
}

NOTE: this method only work when textView width is wrap_content.

Reza Abedi
  • 419
  • 4
  • 16