Android:比 android:ellipsize="end" 更好的东西添加“..."截断长字符串? [英] Android: Something better than android:ellipsize="end" to add "..." to truncated long Strings?

查看:23
本文介绍了Android:比 android:ellipsize="end" 更好的东西添加“..."截断长字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个属性使得

短字和超长字"

短和"

.但我想拥有一些东西.喜欢

. But I want to have smth. like

又短又长……"

现在我截断了 Java 代码中的字符串.但是,那是基于字符数而不是链接的实际长度.所以,结果不是很好.

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

现在它真的变得时髦了!我只是设置了 singleLine=true 并删除了 maxLine(无论是否设置 ellipsize 属性都会出现该错误)...

Now it really gets funky! I just set singleLine=true and removed maxLine (The bug appears with and without setting ellipsize attribute)...

这是从 Motorola Milestone 和 android 2.1 update 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

现在我使用 android:ellipsize="marquee".这似乎是唯一正常工作的设置.它也只有在聚焦时才会移动.我也在许多其他应用程序中看到它.我猜它是常见的做法.

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:比 android:ellipsize="end" 更好的东西添加“..."截断长字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆