Android TextView content too long plus ellipsis, click to show All content

Source: Internet
Author: User

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

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.