Android: is something better than android: ellipsize = "end" to add "..." to shortened long lines?

This property makes

"short and very long word"

to

"short and

. But I want to have something. as

"short and very long ..."

Right now I'm truncating a line in Java code. However, this depends on the number of characters, and not on the actual length of the link. So, the result is not very pleasant.

String title; if(model.getOrganization().length() > 19) { title = model.getText().substring(0, 15).trim() + "…"; } else { title = model.getText(); } ((TextView) findViewById(R.id.TextViewTitle)).setText(title); 

Update

Just noticed, this property actually adds "..." in several cases. But not in all of them:

12345678901234567890 becomes "12345678901234 ..."

However

"1234567890 1234567890" becomes "1234567890" and not "1234567890 123 ..."

Update 2

Now it's really funky! I just set singleLine = true and removed maxLine (an error appears with and without the ellipsize attribute) ...

alt text

This is a screenshot from Motorola Milestone with android 2.1 update. The same thing happens with HTC Desire with the same version of Android.

Update 3

Now I am using android: ellipsize = "marquee". This seems to be the only correct working setting. It also moves only when focusing. I also see this in many other applications. I assume this is a common practice.

+43
android string android-layout layout truncate
Sep 22 '10 at 12:19
source share
4 answers

See my update 3. The "marquee" was used in the workaround. At this time, I saw many applications. Now, with newer versions of Android, this feature is most likely fixed and will work as expected. (my hunch)

+1
Jan 22 '13 at 21:35
source share

If it is for one line, try the following:

 android:ellipsize="end" android:maxLines="1" android:scrollHorizontally="true" android:singleLine="true" 

It worked for me.

+60
Jun 12 '12 at 18:18
source share

I had a similar problem and setting this property in TextView helped:

 android:singleLine="true" 

In addition, I used RelativeLayout, so I limited the space that the TextView could take by setting the left margin on the button to the right of the TextView so that the text could not expand further and was forced to crop its contents.

This may not be the solution to your problem, but it helped me in a similar situation.

+22
Sep 22 '10 at 14:20
source share

Perhaps you can take a look at how the private Ellipsizer class used by the operating system works and change it for your application?

Edit: Here's the working link - http://androidxref.com/5.1.0_r1/xref/frameworks/base/core/java/android/text/Layout.java#1830

+1
Sep 22 '10 at 16:51
source share



All Articles