Android achieves the running horse light effect (more than two running horse lights can be implemented), android running horse lights

Source: Internet
Author: User

Android achieves the running horse light effect (more than two running horse lights can be implemented), android running horse lights
This article uses the MarqueeTextView inherited from TextView to achieve the effect of the running horse. The reason is that the effect of the marquee is that the TextView has focus to run. Sometimes, it takes a little time to get the focus of TextView, resulting in waiting for a period of time to see the effect of running the horse. In addition, by default, only one TextView is in the focused state, and when there are no less than two lawn lights on the page, TextView is hard to implement.


MarqueeTextView class code:

public class MarqueeTextView extends TextView{public MarqueeTextView(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}@Overrideprotected void onFocusChanged(boolean focused, int direction,Rect previouslyFocusedRect) {// TODO Auto-generated method stubsuper.onFocusChanged(focused, direction, previouslyFocusedRect);}@Overridepublic void onWindowFocusChanged(boolean hasWindowFocus) {// TODO Auto-generated method stubif(hasWindowFocus) super.onWindowFocusChanged(hasWindowFocus);}@Override@ExportedProperty(category = "focus")public boolean isFocused() {return true;}}


Code related to the XML layout file:

<Com. barry. components. marqueeTextView android: layout_width = "0dp" android: layout_height = "match_parent" android: layout_weight = "1.0" android: ellipsize = "marquee" android: focusable = "true" android: focusableInTouchMode = "true" android: freezesText = "true" android: marqueeRepeatLimit = "marquee_forever" android: paddingLeft = "10dp" android: paddingRight = "10dp" android: scrollHorizontally = "true" android: singleLine = "t Rue "/> <! -- Width is set to the specific size. --!>





How to achieve the effect of two lawn lights on the same webpage

Duplicate names
Simple Method: Rename
Copy the code again, and change the names of all the demos, demo1, demo2, Marquee, and MyMar copied. For example, add two to all the demos, such as demo22.
Rename the demo and demo1 of the first 2nd runners-up lamps, which is the same as the name changed above.

TextView source code

Use custom TextViewpublic class extends TextView {public AlwaysMarqueeTextView (Context context) {super (context); // TODO Auto-generated constructor stub} public AlwaysMarqueeTextView (Context context, AttributeSet attrs) {super (context, attrs);} public AlwaysMarqueeTextView (Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle);} @ Override public boolean isFocused () {return true ;}@ Override protected void onFocusChanged (boolean focused, int direction, Rect previuslyfocusedrect) {if (focused) super. onFocusChanged (focused, direction, previuslyfocusedrect);} @ Override public void onWindowFocusChanged (boolean focused) {if (focused) super. onWindowFocusChanged (focused);} xml <com. example. usage: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_gravity = "center_vertical" android: layout_marginLeft = "10dp" android: ellipsize = "marquee" android: focusable = "true" android: focusableInTouchMode = "true" android: marqueeRepeatLimit = "marquee_forever" android: singleLine = "true" android: text = "here is the announcement of Tianxiang lighting .... use text marquee effects .... use text marquee effects .... use text marquee effects .... use text marquee effects .... use text marquee effects .... use text marquee effect "/>

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.