Talking about the effect of TextView ellipsize and the Happy Lantern

Source: Internet
Author: User

Speaking of TextView effect, I believe we must be familiar with the lantern.

First look at what Ellipsize is, ellipsize from the development of technical translation to omit the effect. So the name Incredibles, that is, when the text can not be displayed all, what effect to display the parts that are not displayed.

One, what's ellipsize and how?

First, we need to define this in the Android XML.

 <  textview  android:id  = "@+id/textview"   Android: Layout_width  = "Wrap_content"   Android: Layout_height  = "30DP"   Android:text  = "@string/hello_world"//All text is: Hello world! this is a marquee for testing, so the number of words must be more, But it's definitely over 15 words.   android:ellipsize  = "End"   Android:singleline  = "true"   = "20sp"  />
       

Display effect:

You can see that after this paragraph there are three "..." to indicate that the sentence is not finished, and there is a part behind it. So the question is, how did this effect come about?

Android:ellipsize= "End" android:singleline= "true"

This is the two lines of code that work.

Android:singleline= "True" is used to specify the current TextView as a single-line display, meaning that regardless of the number of words, a line to display, this is to show the ellipsize effect of the necessary conditions.

As for why the need to android:singleline= "true" after the source will be said. Let's look at the Android:ellipsize property again.

It is defined by an enumeration in TextView, and we look at this data structure:

   Public enum truncateat {        START,        Middle,        END,        MARQUEE,        /**         * @hide          */        end_small    }

The meaning of Truncateat from the enumeration name: where to truncate. As the name implies, the truncation effect is displayed in the TextView content. The following graphs represent the effects of each variable:

Truncateat.marquee is the marquee effect. But it was supposed to be a line of text scrolling from the right, but actually just adding

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

These two properties, see that is the way. Carefully you will find that it is not a common effect: "To" the second half of the word has gradual transparency, the following will explain the reason why the marquee effect does not show.

In fact, in the actual Android XML also has a property android:ellipsize= "None", this means that does not specify the ellipsis effect:

We can see that the word "test" is more than two characters, but "try" is truncated. In fact, the default value of Android:ellipsize is end. Because there is such a line of code in the TextView constructor:

   if null && ellipsize < 0) {                //  END        }

This means that even if you only set the Android:singleline= "true". The effect of android:ellipsize= "End" is also displayed.

Two, why run lanterns no effect?

For this problem, as we all know, when we write the following code:

  <TextView        android:id= "@+id/textview"        android:layout_width= "Wrap_content"         Android:layout_height= "30DP"        android:text= "@string/hello_world"        android:ellipsize = "marquee"        android:singleline= "true"        android:textsize= "20sp"        />

But found that the application is running when the marquee effect is not. Mother Egg, this is for fur. This time compared to everyone can Baidu to solution. Here are two of the most popular solutions on the Web

1. Rewrite TextView

2. You need to call textviews a whole bunch of functions.

at first I saw this very uncomfortable, but also can play well, mom eggs,android:ellipsize= "Start|middle|end" can be a line of code display, for Mao this does not. The reason why you want to know the problem is simple.

Knowing why, you'll know how.

When it comes to the marquee, there is still a bit of content inside. The following first describes a few

Talking about the effect of TextView ellipsize and the Happy Lantern

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.