Android realizes the marquee effect

Source: Internet
Author: User

First step: Create a new project, Marqueetextview
First, in order to observe the marquee effect, the text that will be displayed is likely to be long written. In the Strings.xml folder, the

<stringname="hello_world">hello_world</string>

Revision changed to

<stringname="hello_world">我的代码很长,真的很长,不行你看看,实际上是骗你的,逗比,hiahia~~~~</string>

By default, the display text wraps automatically! In order to achieve a marquee effect, you first want to prevent it from wrapping itself. Implemented by using the Singleline Property!
Android:singleline= "true"
If the goal is only to achieve the single-line text of the marquee effect, can only be achieved by three statements!
Android has a Ellipsize property,
Android:ellipsize= "Marquee"
Android:focusable= "true"
Android:focusableintouchmode= "true"

Through the above code can achieve single-line text of the marquee effect. However, if you want to achieve multi-line text of the marquee effect, the above code repeated writing, can not achieve the desired function! Because in the focusable attribute above, the focus has been defined on the first line! The follow-up was not focus!. Can be achieved by creating a new class Class!

In the SRC folder, create a new class named MarqueeText

 PackageCom.example.marqueetextviewdemo1;ImportAndroid.content.Context;ImportAndroid.util.AttributeSet;ImportAndroid.widget.TextView; Public  class marqueetext extends TextView{     Public MarqueeText(Context context) {Super(context);//TODO auto-generated constructor stub} Public MarqueeText(context context, AttributeSet attrs,intDefstyle) {Super(Context, attrs, Defstyle);//TODO auto-generated constructor stub} Public MarqueeText(context context, AttributeSet attrs) {Super(context, attrs);//TODO auto-generated constructor stub} Public Boolean isFocused() {return true; }}

The TextView in the Main.xml file is then modified to the package name +.+ class name.
This revision is meant to be all defined in this way, to get focus, and then achieve the effect of the marquee!

The results shown are as follows:

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android realizes the marquee effect

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.