TextView text horizontal scrolling (marquee effect)

Source: Internet
Author: User

TextView requires the following key points to implement text scrolling: 1. The text length is longer than the display range: android: singleLine = "true"; 2. You can set the scrolling or display style: android: ellipsize = "marquee"; 3. The TextView class can be rewritten only when the focus is obtained. (However, if the focus is always given, it may not be clicked, such as when it is placed in the listView) 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 defStyle) {super (context, attrs, defStyle);} // always returns true, that is, always get focus @ Overridepublic boole An isFocused () {return true;} added TextView in the layout file: android: singleLine = "true" android: focusable = "true" android: marqueeRepeatLimit = "marquee_forever" // The number of scrolling times. At this time, the number of scrolling times is countless android: ellipsize = "marquee" ellipsize attribute setting how to display the control when the text is too long. You can set the following values: "start" -- ellipsis () at the beginning, "end" -- ellipsis () at the end, and "middle" -- ellipsis () in the middle; "marquee"-displayed as a marquee (horizontal movement of the animation)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.