[How to set the horizontal scrolling effect in TextView in Androidui effects]android

Source: Internet
Author: User

How to make the text achieve merry effect, the following to achieve the next bar ~~~~~~

 PackageIRDC. Scrollingtext;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.widget.TextView; Public classScrollingtextextendsactivity{ PublicTextView T1; /**Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.main); T1=(TextView) Findviewbyid (R.ID.T1); T1.settext ("Haha my lantern program Next is the lyrics hehe: Chenyuluoyan, Biyuexiuhua, the United States of nowhere to hide, people in the side, such as Mu Spring"); T1.settextsize (30); T1.sethorizontallyscrolling (true); T1.setfocusable (true); }}

In this program I set the focus of T1 to true (meaning focus on T1), colleague I set the T1 text display can exceed its display area (T1.sethorizontallyscrolling (True) set the purpose of this line is to not let the program automatically to the text wrapping To make it a single line), and of course these attributes can be defined in the XML file. Next we look at the Main.xml file.

<?XML version= "1.0" encoding= "Utf-8"?><AbsolutelayoutAndroid:id= "@+id/widget35"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:background= "@drawable/black"xmlns:android= "Http://schemas.android.com/apk/res/android"><TextViewAndroid:id= "@+id/t1"Android:layout_width= "100px"The width of the text display area This value must be smaller than the width of your text or it will be ineffective android:layout_height= "Wrap_content"Android:text= "@string/str_id"Android:textcolor= "@drawable/green"android:layout_x= "61px"android:layout_y= "69px"ANDROID:SCROLLX= "2px"Android:singleline= "true"android:ellipsize= "Marquee"Android:marqueerepeatlimit= "Marquee_forever"></TextView><viewstubandroid:layout_y= "221dip"android:layout_;wrap_content "Android:layout_x= "103dip"Android:id= "@+id/viewstub01"Android:layout_height= "Wrap_content"></viewstub></Absolutelayout>
It is noted that in TextView I added three lines of blue fields, where Singleline represents a single line of text in TextView if you set sethorizontallyscrolling in your program (TRUE) in this you can not write anymore, And then there's our key point. ellipsize= "Marquee" This statement indicates that we set the TextView to a merry, marqueerepeatlimit= "Marquee_forever" indicates the number of repetitions of the merry scrolling effect, You can fill in a natural number. All right, I got the build, try it.
Reprinted from: http://www.lupaworld.com/home/space-345712-do-blog-id-138560.html

How to set the horizontal scrolling effect in TextView in Androidui effects]android

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.