Android TextView FAQ and usage summary, androidtextview

Source: Internet
Author: User

Android TextView FAQ and usage summary, androidtextview

1. Set the number of lines for text display
1. display only one line of text android: singleLine = "true"
SetTransformationMethod (TransformationMethod)
2. Set the maximum number of lines of text to be displayed.
Android: maxLines = "3"
TextView. setMaxLines (3 );

3. after setting the maximum number of lines for text display, but the text may not be completely displayed, you can set the omitted symbol, indicating that there is still content not displayed android: ellipsize = "end" end-ellipsis at the end, the most common method is to start-ellipsis at the beginning of the middle-ellipsis in the middle of the marquee-marquee display, always execute text scrolling animation, affecting performance
4. Do Not Display padding
Android: includeFontPadding = "false"

5. Line spacing
Android: lineSpacingExtra = ""

2. Set the text display length. 1. Set the maximum display length. Unit: pxandroid: maxWidth = ""/TextView. setMaxWidth (int)
Three textviews in the middle left and right use the RelativeLayout layout. If the text in the middle changes the length, it is not automatically adjusted. As a result, the text on the right is still right
Use maxWidth to solve the above problems


2. maximum number of characters displayed: android: maxLength = ""/TextView. setFilters (InputFilter) does not distinguish Chinese from English. For example, if it is set to 3, three Chinese characters can be displayed, but only three English words can be displayed.
3. Note that TextView. setSize (pxValue) and setTextSize (TypedValue. COMPLEX_UNIT_PX, pxValue) cannot be used directly to modify the text size dynamically );
For details about the text size type, see the TypedValue document.

3. Set different style texts in TextView
1. Text placeholders
In some cases, most of the characters are fixed, and only one or two characters in the middle are changed. In addition, we want to declare the text part in string. xml. For example, "July March 14, 2015"
In res/values/string. xml
<Resources>
<String name = "date"> July 1, $ d </string>
</Resources>

TextView. setText (getResoure. getString (R. string. date, 14 ));
$ D is a placeholder. For more information, see Formatterhttp: // developer.android.com/reference/java/util/Formatter.html.

2. Multiple colors of a line of text <resources>
<String name = "love_world"> & lt; font color = \ "# aaaaaa \" & gt; % 1 $ s text & lt;/font & gt; </string>
</Resources>

String string = getResources (). 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 ));

4. android drawTextTextView note
The baseLine to Bottom distance http://blog.csdn.net/liucheng2009/article/details/7053837 is ignored

Related Article

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.