First, the text display line number setting
1. Display only one line of text android:singleline= "true"
Settransformationmethod (Transformationmethod)
2. Set up to display a few lines of text
Android:maxlines= "3"
Textview.setmaxlines (3);
3. After setting the maximum number of lines of text, but the text may not be complete, you can set the ellipsis, indicating that the content has not yet shown android:ellipsize= "End" end-ellipsis at the end, the most common way to start-ellipsis at the beginning middle- Ellipsis in the Middle marquee-a marquee display that always performs text scrolling animations that affect performance
4. Do not display padding
Android:includefontpadding= "false"
5. Line Spacing
Android:linespacingextra= ""
Second, the text display length setting 1. Set maximum display length in pxandroid:maxwidth= ""/textview.setmaxwidth (int)
Left and right three TextView use relativelayout layout, the middle of the text if it will change the length, will not automatically adjust, resulting in the right side of the text or on the right
Use MaxWidth to solve these problems
2. Maximum number of characters android:maxlength= ""/textview.setfilters (Inputfilter) does not distinguish between Chinese or English, for example, setting 3, can display 3 kanji, but only 3 English words can be displayed.
3. Dynamic modification of text size needs to be noted, can not directly use Textview.setsize (Pxvalue); Settextsize (typedvalue.complex_unit_px, Pxvalue);
Text size type See Typedvalue documentation
Three, TextView set different style text
1. Text placeholders
Some times a character is mostly fixed, only the middle one or two bits are variable, and you want to make the declaration text part in String.xml. For example: "March 14, 2015"
In the Res/values/string.xml
<resources>
<string name= "Date" >2015 March%1$d Day </string>
</resources>
Textview.settext (Getresoure.getstring (R.string.date, 14));
$d is a placeholder for more information, see document Formatterhttp://developer.android.com/reference/java/util/Formatter.html
2. Multiple colors in one line of text<resources>
<string name= "Love_world" ><font color=\ "#aaaaaa \" >%1$s text section </font> </string>
</resources>
A String string = Getresources () is required for use. getString (r.string.Love_world, NAMESTR);
Textview.settext (html.fromhtml(string));
3. Click the text to change the color Textview.settextcolor (getresources (). Getcolorstatelist (R.color.selector));
Four, Android Drawtexttextview note
Ignoring the distance from baseline to bottom http://blog.csdn.net/liucheng2009/article/details/7053837
Android TextView FAQs and Usage Summary