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 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

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.