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