Android implements a way to omit the part or scroll display when TextView text is too long _android

Source: Internet
Author: User

The example in this article describes the way Android implements a partial or scrolling display when TextView text is too long. Share to everyone for your reference, specific as follows:

There is a Ellipsize property in the TextView that shows how the control should appear when the text is too long, as explained below:

1.android:ellipsize= "Start"-– ellipses appear at the beginning
2.android:ellipsize= "End"--ellipses appear at the ends
3.android:ellipsize= "Middle"--ellipses appear in the middle
4.android:ellipsize= "Marquee" – Display as a racing lamp (animations move laterally)

The text scrolls around three properties:

Android:singleline= "true"
android:ellipsize= "marquee"
android:marqueerepeatlimit= "Marquee_forever"

Android in order to achieve the text of the scrolling can be embedded in the ScrollView a textview, in fact, TextView can also achieve multiline scrolling, after all, ScrollView must have only a direct subclass of the layout. Simply setting a few properties in layout can be easily implemented.

<textview
android:id= "@+id/tvcwj"
android:layout_width= "Fill_parent"
Wrap_content "
android:scrollbars=" Vertical <!--vertical scroll bar-->
android:singleline= "false" <!--implement multiple lines- >
android:maxlines= <!--no more than 15 lines-->
android:textcolor= "#FF0000"
/>
< TextView
 android:id = "@+id/app_shortcontent"
 android:layout_width = "Wrap_content"
 android:layout_height = " Wrap_content "
 android:singleline =" true "
 Android:textcolor =" #FFFFFFFF "
 android: scrollhorizontally = "true"
 android:focusable = "true"
 android:ellipsize = "marquee"
 Android: Marqueerepeatlimit = "Marquee_forever"/>

Of course, in order for TextView to move, we also need to use the TextView Setmovementmethod method to set a scrolling instance, the following code

TextView TV = (TextView) Findviewbyid (R.ID.TVCWJ);
Tv.setmovementmethod (Scrollingmovementmethod.getinstance ()); Android Development Network prompts relevant to view the SDK

Android.text.method Branch Learn More

Report:

By the way, TextView the implementation of automatic scrolling, here are two methods:

One, in the code to achieve:

Textview.setellipsize (TextUtils.TruncateAt.MARQUEE);
Textview.setsingleline (true);
Textview.setmarqueerepeatlimit (6);

Two, in the XML implementation:

<textview android:id= "@+id/textview01" android:layout_width= wrap_content "android:layout_height=" Wrap_
Content "Android:singleline=" true "
android:text=" DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD "
android:marqueerepeatlimit=" Marquee_ Forever "android:ellipsize=" marquee "
android:scrollhorizontally= true" android:width= "150dip" ></ Textview>

All OK, when TextView gets focus, it scrolls automatically.

Add:

Whether it's manual or automatic, you have to add ScrollView to scroll.

The ScrollView Scrollto method can be invoked by handle to scroll

Handler Mhandler = new Handler ();
Private Runnable Mscrolltobottom = new Runnable () {public
void run () {
mscrollview.scrollto (0, offset);
}
};

Ontouch Inside:

Mhandler.post (Mscrolltobottom);

Add:

1. Set the ellipsize of the TextView to marquee (said above)
2. Set the deprecated single to True
3. Set TextView Marquee Repeat limit properties (scroll back number, default is countless back)

Put a code on it:

Textview.setellipsize (TextUtils.TruncateAt.MARQUEE);
Textview.setsingleline (true);
Textview.setmarqueerepeatlimit (6);

More interested readers of Android related content can view this site: "Android scroll bar and Rolling tips summary", "Android graphics and image processing skills summary", "Android Development introduction and Advanced Course", " Android Debugging tips and FAQ Solutions Summary, Android Multimedia tips summary (audio, video, audio, etc.), "Android Basic Components Usage Summary", "Android View Summary", " Android Layout layout Tips and a summary of the use of Android controls

I hope this article will help you with the Android program.

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.