TextView and textview

Source: Internet
Author: User

TextView and textview

Reprinted: http://www.2cto.com/kf/201409/330658.html

1. What should I do if I only want TextView to display a row, but the text exceeds the length of TextView?
Show ellipsis at the beginning

android:singleLine="true" android:ellipsize="start"

Show ellipsis at the end

android:singleLine="true" android:ellipsize="end"

Show ellipsis in the middle

android:singleLine="true" android:ellipsize="middle"

Automatic horizontal scrolling (running horse light effect)

android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true"

Android: singleLine = "true" must be added to all the above four effects, because TextView will automatically wrap by default.

Android: ellipsize indicates how to display long text

Android: marqueeRepeatLimit = "marquee_forever" indicates that the settings are always repeated. You can also set specific numbers.

Android: focusable = "true" and android: focusableInTouchMode = "true" must be added. Otherwise, the rolling effect will fail.

2. How can I make TextView scroll vertically?
Add the following sentence to the Java code to implement vertical scrolling: textView. setMovementMethod (ScrollingMovementMethod. getInstance ());

3. How can I change the content of TextView?

Override TextView to keep TextView selected: AlwaysMarqueeTextView. java

/** Override TextView to ensure that the running horse lights remain displayed */public class AlwaysMarqueeTextView extends TextView {public AlwaysMarqueeTextView (Context context) {super (context);} public AlwaysMarqueeTextView (Context context, AttributeSet attrs) {super (context, attrs);} public AlwaysMarqueeTextView (Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle);} @ Override public boolean isFocused () {return true; // be sure to set it to true }}

 

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.