Android TextView FAQs and Usage Summary

Source: Internet
Author: User


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" >&lt;font color=\ "#aaaaaa \" &gt;%1$s text section &lt;/font&gt; </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

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.