Why Is Marquee Not Working In Widget?

亡梦爱人 提交于 2019-12-01 07:31:11

I guess it is the following Problem:

the Method setText(CharSequence) is resetting the MarqueeRepeatLimit. The Method setText(CharSequence) is a RemotableViewMethod, which means you cann access it from a RemoteView. The setMarqueeRepeatLimit() hasn't this special annotation. I see no way, how you could set the Text and keep your Marquee state inside a RemoteView. Maybe the SetText Method from TextView helps you a little

private void setText(CharSequence text, BufferType type,
                     boolean notifyBefore, int oldlen) {
    if (text == null) {
        text = "";
    }

    if (!mUserSetTextScaleX) mTextPaint.setTextScaleX(1.0f);

    if (text instanceof Spanned &&
        ((Spanned) text).getSpanStart(TextUtils.TruncateAt.MARQUEE) >= 0) {
        setHorizontalFadingEdgeEnabled(true);
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
    }

    int n = mFilters.length;
    for (int i = 0; i < n; i++) {
        CharSequence out = mFilters[i].filter(text, 0, text.length(),
                                              EMPTY_SPANNED, 0, 0);
        if (out != null) {
            text = out;
        }
    }

    if (notifyBefore) {
        if (mText != null) {
            oldlen = mText.length();
            sendBeforeTextChanged(mText, 0, oldlen, text.length());
        } else {
            sendBeforeTextChanged("", 0, 0, text.length());
        }
    }

Make sure to use android:singleLine="true" and android:scrollHorizontally="false" (or remove it completely) in your XML. This should do the trick.

Aayush Puranik

This might work for you

In your layout:

<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:marqueeRepeatLimit="marquee_forever"
android:text=""/>

In your code:

TextView textView = (TextView)findViewById(R.id.TextView03);
textView.setText(";lkjdf;alkdsfjoiawejrokajdsl;fkadmnsflkamndvklahoreiuaweifjakldsmflkhfgoueyhtoaijpkjdflkahndsofuhyoeia");
textView.setHorizontallyScrolling(true);
textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
textView.setSingleLine();
textView.setSelected(true);

Try this. Set the Marquee span before setting the text.

SpannableString buffer = new SpannableString(tickertweets.toString());
buffer.setSpan(TextUtils.TruncateAt.MARQUEE,0, (tickertweets.length() -1) ,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
updateViews.setTextViewText(R.id.ticker, buffer);

you can use this code for scrolling text in textView:

textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
        textView.setSingleLine();
        textView.setMarqueeRepeatLimit(10);
        textView.setFocusable(true);
        textView.setHorizontallyScrolling(true);
        textView.setFocusableInTouchMode(true);
        textView.requestFocus();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!