Android TextView Multi-line text (more than 3 lines) workaround for invalid problem using Ellipsize property

Source: Internet
Author: User

Layout file:

<TextView Android:id="@+id/businesscardsingle_content_abstract"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_margintop="5DP"Android:linespacingmultiplier="1.0"Android:lines="6"Android:text="@string/agrinbusiness_content"Android:textcolor="#7f7f7f"android:textsize="13SP"/>

Control the number of lines of text displayed in Java code:

Viewtreeobserver observer = Textabstract.getviewtreeobserver ();//textabstract for TextView controlsObserver.addongloballayoutlistener (NewOngloballayoutlistener () {@Override Public voidongloballayout () {Viewtreeobserver Obs=textabstract.getviewtreeobserver (); Obs.removeglobalonlayoutlistener ( This);if(Textabstract.getlinecount () >6)//change when you determine how many rows are greater{intLineendindex = Textabstract.getlayout (). Getlineend (5);//set line sixth to make an ellipsisString text = Textabstract.gettext (). subsequence (0, lineendindex-3) +"...";  Textabstract.settext (text); }  }}); 

Android TextView Multi-line text (more than 3 lines) workaround for invalid problem using Ellipsize property

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.