TextView properties in a layout file
Copy Code code 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 how many lines of text are displayed in Java code
Copy Code code as follows:
Viewtreeobserver observer = Textabstract.getviewtreeobserver (); Textabstract as TextView control
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 the 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);
}
}
});