问题
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?
回答1:
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.
回答2:
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.
回答3:
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"/>
来源:https://stackoverflow.com/questions/10458844/textview-marquee-doesnt-work