不同厂商定制的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