In Android TextView, there is an attribute that is too long plus an ellipsis, that is, Ellipsize, 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" is best to add a textview to display the constraints of the number of rows, for example:
Android:singleline= "true" or android:lines= "2"
In the Java file: 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 textview to display the constraints of the number of rows, for example:
Tv.setsingleline (TRUE);
This property is not only available for TextView, but also for Editext, but it does not support marquee.
Text expansion and contraction
public class Demoactivity extends Baseactivity {
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main);
The android:singleline= "true" final TextView TV = (TextView) Findviewbyid (R.id.task_2_title) is set in the XML file; Tv.setmovementmethod (Scrollingmovementmethod.getinstance ()); Tv.setonclicklistener (New Onclicklistener () {Boolean flag = true; @Override public void OnClick (View v) {log.i ("Tv.getlinecount ()", tv.getheight () + ""); if (flag) {flag = false; Tv.setellipsize (NULL); Expand//tv.setsingleline (flag); }else{flag = true; Tv.setellipsize (TextUtils.TruncateAt.END); Contraction//tv.setsingleline (flag); } } }); } }
Actually, just empty the style. can be fully unfolded.
Someone might say, what if I want to start a few lines? Rest assured, as can be. On the code:
The following properties are set in the XML file:
Android:lines= "4"//4 rows I initialized
Activity over there code, just a little bit.
if (flag) {flag = false; Tv.setellipsize (NULL); Expand Tv.setsingleline (flag); }else{flag = true; Tv.setellipsize (TextUtils.TruncateAt.END); The purpose of setting Setsingleline is to cancel the fixed value of lines== "4".
Reference: http://blog.csdn.net/wwzqj/article/details/8731859