Android uses TextView to achieve a marquee effect (1)

Source: Internet
Author: User

Android uses TextView to achieve a marquee effect

1.activity_main.xml

<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
tools:context= "Com.imooc.marqueetextviewdemo.MainActivity" >

<textview
        Android:id= "@+id/tv_01"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/name"/>

</RelativeLayout>

2.text text content:
Strings.xml:
<resources>
<string name= "App_name" >MarqueeTextViewDemo</string>
<string name= "Name" >marqueetextviewdemo,marqueetextviewdemo,marqueetextviewdemo,marqueetextviewdemo</ String>
</resources>

Legend:

There is too much text before any properties are set, and word wrapping is displayed.

3. Set up one-line marquee
Just add 4 properties to the TextView

Android:singleline= "true"//sets the text to be displayed on one line, the text not displayed with three "..." Display

Android:ellipsize= "marquee"//Get rid of three "..."

Android:focusable= "true"
Android:focusableintouchmode= "true"

Complete code example:
<textview
Android:id= "@+id/tv_01"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/name"
Android:singleline= "true"
Android:ellipsize= "Marquee"
Android:focusable= "true"
Android:focusableintouchmode= "true"
/>

Legend:

Layout display style is not running, the whole line is one.

Run Example:

The text starts the marquee.

Android uses TextView to achieve a marquee effect (1)

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.