[Original] Open Android TextView Marquee

Pro test possible. code directly.
Test machine: XiaoMi 2S Android 5.0

<TextView
    android:id="@+id/toolbar_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:fadingEdge="none"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:freezesText="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:singleLine="true"
    android:scrollHorizontally="true"
    android:textColor="#fff"
    android:textSize="16sp" />

mToolbarTitle.setSelected (true);

Note:
The following lines in the XML are required:
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"

Finally, don't forget that JAVA also needs to call the setSelected(true) method of TextView.

Special attention:
At present, it is found that the writing method of android:singleLine="true" needs to be abandoned, but at present, only Marquee can be written in this way to take effect. If you change to the latest writing android:maxLines="1", you will find that Marquee cannot scroll. do not know why. If anyone knows the reason, or if there is a better way to write it, you are welcome to discuss it enthusiastically.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326192424&siteId=291194637