您的位置:首页 > 产品设计 > UI/UE

TextView:ellipsize设置了Marquee显示省略号

2014-05-30 17:56 1361 查看
不同厂商定制的Android系统,TextView:ellipsize设置了Marquee显示省略号(如全志平台),解决办法:

查看TextView源码发现有一段代码涉及到ViewConfiguration

if (ViewConfiguration.get(context).isFadingMarqueeEnabled()) {
setHorizontalFadingEdgeEnabled(true);
mMarqueeFadeMode = MARQUEE_FADE_NORMAL;
} else {
setHorizontalFadingEdgeEnabled(false);
mMarqueeFadeMode = MARQUEE_FADE_SWITCH_SHOW_ELLIPSIS;
}
setEllipsize(TextUtils.TruncateAt.MARQUEE);

isFadingMarqueeEnabled函数是被google hide掉的函数,由厂商编译framework时hardcode。

在activity oncreate时通过ViewConfiguration.get方法获取实例,再通过该实例反射设置ViewConfiguration的mFadingMarqueeEnabled

变量为true即可修复本文开头提到的bug。(代码如下)

ViewConfiguration configuration =ViewConfiguration.get(this);
Class claz =configuration.getClass();
try {
Field field=claz.getDeclaredField("mFadingMarqueeEnabled");
field.setAccessible(true);
      field.set(configuration, true); 

} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();

catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

参考:http://www.myexception.cn/mobile/1493703.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐