安卓:东西比Android好:ellipsize ="末"要将" ..."以截断长字符串? [英] Android: Something better than android:ellipsize="end" to add "..." to truncated long Strings?
问题描述
<一个href="http://stackoverflow.com/questions/1666736/android-textview-automatically-truncate-and-replace-last-3-char-of-string">This物业使得
短,很长字的
到
短和
。但我想有不便。像
短,很-LON ......
"short and very-lon..."
现在我截断在Java中code中的字符串。然而,这就是根据字符数,而不是链路的实际长度。所以,结果是不是很漂亮。
Right now I truncate the String in Java code. However, thats based on the number of characters and not the actual length of the link. So, the result isn't very nice.
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);
更新
只注意到,该属性实际上在少数情况下增加了...。但不是在所有的人:
Just noticed, this property actually adds "..." in a few cases. But not in all of them:
12345678901234567890变 12345678901234 ......
12345678901234567890 becomes "12345678901234..."
不过,
1234567890 1234567890 变为1234567890,而不是 1234567890 123 ......
"1234567890 1234567890" becomes "1234567890" and not "1234567890 123..."
更新2
现在真正变得时髦!我只是设置单线=真和去除的MaXLine(这个bug似乎有和没有设置ellipsize属性)...
Now it really gets funky! I just set singleLine=true and removed maxLine (The bug appears with and without setting ellipsize attribute)...
这是一个屏幕截图采取从摩托罗拉Milestone采用Android 2.1更新1.同样发生在HTC Desire采用相同的Android版本
This is a screenshot take from Motorola Milestone with android 2.1 update 1. Same happens on HTC Desire with the same android version
更新3
现在我用安卓ellipsize =金字招牌。这似乎是唯一正确的工作环境。这也是唯一的运动,集中在。我看到它在许多其他应用也。我想它的通行做法。
Now I use android:ellipsize="marquee". That seems to be the only properly working setting. It's also only moving, when focused. I see it in many other apps also. I guess its common practise.
推荐答案
请参阅我的更新3.解决方法是使用字幕。我见过许多应用程序这样做,在这个时候。 现在,随着Android的新版本,这个功能很有可能是固定的,并会按预期工作。 (我猜测)
See my update 3. The workaround was using " marquee". I have seen many apps doing that at this time. Now, with new versions of Android this feature is most likely fixed and will work as expected. (my guess)
这篇关于安卓:东西比Android好:ellipsize =&QUOT;末&QUOT;要将&QUOT; ...&QUOT;以截断长字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!