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)