Android TextView FAQ Summary

Source: Internet
Author: User

Android:singleline= "true" digital English letter display, ellipsis only one point of the problem.

Problem Description:

When using the Singleline property, when a string contains a pure number or letter, an automatically truncated ellipsis has only one point. The problem does not occur with kanji strings or mixed strings.

Problem Solving methods:

It is learned that this is Android4.0 after the native code of the Bug,textview assignment string followed by a full-width space

Singleline= "True" differs from android:maxlines= "1"

Problem Description:

Android TextView has two properties Singline and Maxlines. In the literal sense, both are the number of lines that limit text. So Singleline= "true" and maxline= "1" are all limited to one line, what's the difference?

先看看Google Document 的解释:
android:maxlines makes  The  TextView is at  most of this many lines  Tall. Android:singleline constrains the  text  to  a  single horizontally scrolling line  instead of  letting it  wrap  onto multiple lines , and  advances focus instead of  inserting a  newline when you press the  enter key. 

MaxLines is in the limit height, Singleline is forced to not let the line break. What is the difference between specific effects? From a height is the same, both must show a line, but from the position of the line to be different, maxlines will not change the position of the line, and Singleline will. From this perspective, Singleline's display will be better, because if more than one line of Singleline is displayed in a row, followed by "...". The maxlines= "1" does not, it will still wrap in the original line, so sometimes a row dissatisfaction, but do not show the rest of the section.

同样一句话 maxLines截取之后显示不全,singleLine就会在一行范围内全部显示。例如:鍢庡槑0009912  这个字符串。 maxLines效果是:  鍢 singleLine效果是: 鍢庡槑00如果都加上android:ellipsize=“end” maxLines效果是:  鍢... singleLine效果是: 鍢庡槑00...

In summary, if you want to use ellipses to intercept the string display, we recommend using Singleline. If you want to control the number of lines displayed, it is recommended to use Maxlines.

The use of Android:ellipsize properties

**eidttext and TextView content too long words word wrap, using android:ellipsize and android:singleine can be resolved, so that only one line.

EditText does not support marquee

Use the following:

in XML

android:"end"    省略号在结尾android:"start"   省略号在开头android:"middle"     省略号在中间android:"marquee"  跑马灯android:"true"

Of course, you can also use code statements

Tv. Setellipsize(textutils. Truncateat. ValueOf("END"));Tv. Setellipsize(textutils. Truncateat. ValueOf("START"));Tv. Setellipsize(textutils. Truncateat. ValueOf("Middle"));Tv. Setellipsize(textutils. Truncateat. ValueOf("MARQUEE"));Tv. Setsingleline(true);
The problem of android:ellipsize and Android:maxlines attribute conflict

Problem Description:

When the text content in TextView is longer than the width of the TextView, if it is a single line, the excess will be truncated, and we will use Android:ellipsize, which can be used to omit the display text, but it is probably not working as we thought.

Many people think that this is a property conflict caused, but it is not.

The red below is important because Singleline = True may be set in the generic control;
So direct use of Setmaxlines (n), is not working

Here's how to fix it:

TextView tv_text = (TextView) vDescParent.findViewById(R.id.tv_text);tv_text.setText(ss.toString());// 设置可以多行显示tv_text.setSingleLine(false);tv_text.setMaxLines(3);tv_text.setEllipsize(TextUtils.TruncateAt.valueOf("END"));

Or:

Android中android:ellipsize与android:maxLines属性不冲突,只是跟append()方法冲突,需要把内容拼成一字符串然后setText()

Android TextView FAQ 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.