Recently, in order to solve a bug, if the content in textview is too long, automatic line feed is triggered. However, when the measuretext function is called, the returned value is inaccurate, and the Unit is not determined.
Pixel or dip are not allowed. Later I remembered that the textview had an attribute with excessive content and ellipsis (ellipsize), which could solve this problem more lazy. Haha ~
The usage is as follows:
In XML
Android: ellipsize = "end" ellipsis at the end
Android: ellipsize = "start" ellipsis at the beginning
Android: ellipsize = "Middle" ellipsis in the middle
Android: ellipsize = "marquee"
It is best to add a constraint Android: singleline = "true"
You can also useCodeStatement
TV. setellipsize (textutils. truncateat. valueof ("end "));
TV. setellipsize (textutils. truncateat. valueof ("START "));
TV. setellipsize (textutils. truncateat. valueof ("Middle "));
TV. setellipsize (textutils. truncateat. valueof ("marquee "));
It is best to add a constraint TV. setsingleline (true );
This attribute is not only available for textview, but also for editext, but it does not support marquee