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...