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, the text may not appear full. The ability to set ellipsis symbols. Indicates that the content has not yet been displayed android:ellipsize= "End" end-ellipsis at the end. Most often used by the start-ellipsis at the beginning of the middle-ellipsis in the middle marquee-the marquee displays, always running text scrolling animations. Impact performance
4. Do not display padding
Android:includefontpadding= "false"
5. Line Spacing
Android:linespacingextra= ""
Second, the text display length setting 1. Sets the maximum display length. Unit is pxandroid:maxwidth= ""/textview.setmaxwidth (int)
Left and right three TextView use relativelayout layout, the middle of the text is assumed to change the length of the words, do not actively 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 and English. For example, set 3, can display 3 characters, but also can only display 3 English words.
3. Dynamic changes in text size need to be noted. No direct use of textview.setsize (Pxvalue); Settextsize (typedvalue.complex_unit_px, Pxvalue);
Text size type See Typedvalue documentation
Three, TextView set different text
1. Text placeholders
In some cases, most of the characters are 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, a lot of other information is described in 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>
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
Five, set the text to use what unituse dip for text size. Because even though the screen density of the same different phone SP converted to PX value inconsistent
Android TextView FAQs and Usage Summary