In Android TextView, there is an attribute that is too long plus an ellipsis, that is, Ellipsize, as follows:
In the XML:
Android:ellipsize="end" ellipsis at the end android:ellipsize ="start " ellipsis at the beginning android:ellipsize="Middle" Ellipsis in middle android:ellipsize="marquee" Marquee
It 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
Android TextView content too long plus ellipsis, click to show All content --Geneva- in Ten:Geneva: $I'd like to say a couple of King's collections I want to contribute. In Android TextView, there is an attribute with an ellipsis in the content, that is, Ellipsize, as follows: in XML: android:ellipsize< /c7>="End"ellipsis at the end android:ellipsize="Start"ellipsis at the beginning Android:ellipsize="Middle"ellipsis in the middle android:ellipsize="Marquee"It's 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 constraint that displays 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 classDemoactivity extends Baseactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); //android:singleline= "True" is set in the XML fileFinal TextView TV =(TextView) Findviewbyid (r.id.task_2_title); //Tv.setmovementmethod (Scrollingmovementmethod.getinstance ());Tv.setonclicklistener (NewOnclicklistener () {Boolean flag=true; @Override Public voidOnClick (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); //Shrinkage//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 attributes are set in the XML file: android:lines= "4"//I initialize 4 lines activity over there code, just a little bit.
if (flag) { false; Tv.setellipsize (null// expand tv.setsingleline (flag); } Else { true; // Shrink }
The purpose of setting the Setsingleline is to cancel the fixed value of lines== "4"
Android TextView content too long plus ellipsis, click to show All content