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

Source: Internet
Author: User

This article describes a workaround for the Android TextView multi-line text (more than 3 lines) using the Ellipsize property invalidation problem, and a friend who needs to refer to the TextView property in the layout fileCopy CodeThe code is as follows:
<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

Copy CodeThe code is as follows:
Viewtreeobserver observer = Textabstract.getviewtreeobserver (); Textabstract for TextView controls
Observer.addongloballayoutlistener (New Ongloballayoutlistener () {

@Override
public void Ongloballayout () {
Viewtreeobserver Obs = Textabstract.getviewtreeobserver ();
Obs.removeglobalonlayoutlistener (this);
if (Textabstract.getlinecount () > 6)//To determine the number of rows is greater than how much change
{
int lineendindex = Textabstract.getlayout (). Getlineend (5); Set line sixth to make an ellipsis
String 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

Related Article

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.