Textview or eidtview .... If the text is too long, the text will be displayed...

Source: Internet
Author: User

About textview or eidtview .... If the text is too long,

How to make the last part of the screen display, but also to adapt to different sizes of the screen (it is best to adapt to the horizontal and vertical screen switching)

At that time, in order to get started, I wrote a method (I despise myself first)

String show = notice. gettext ();
Show = show. Length ()> 18? Show. substring (0, 18) + "...": show;

This method is incredibly vulnerable. First, if the English and Chinese characters are mixed, the character length cannot be determined.

Let alone switching between screens of different sizes and horizontal and vertical screens

 

All right, I can see the wince article written by yigedo on the Internet,

Microsoft has implemented the gettextextentpoint method, and there is no reason to catch up with Android.

Don't do it,

Indeed, after reading the API, Google not only did it, but also did better,

There isSetellipsize







Method

Public void

Setellipsize

(Textutils. truncateat

Where)




Method parameter texturils. truncateat:






You can see it. Not only does it add the... front to the back, but it can also be in the middle ,~~~


Summary

Enum values
Textutils. truncateatEnd

Textutils. truncateatMarquee

Textutils. truncateatMiddle

Textutils. truncateatStart

Oh, that's it.


----------


Maybe you have to ask how to get it in the XML file of layout?


Public static final int

Ellipsizesince:
API Level 1

Where to ellipsize text.

Must be one of the following constant values.

Constant Value Description
none
0
start
1
middle
2
end
3
marquee
4

 

Constant Value:

16842923 (0x010100ab)
<Textview
Android: Id = "@ + ID/item_text"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textsize = "16sp"
Android: singleline = "true"
Android: ellipsize = "end"


>
</Textview>

Two points should be emphasized here


Be sure to pay attention, or you will not see what Google has added to you...

Android: layout_width = "wrap_content" this is required

Android: singleline = "true" is not required, because the system may add two rows...






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.