由于Android TextView最大宽度尾部省略号的场景,在内容含有Span的时候,并未对Span处理,导致达到最大宽度尾部无省略号,甚至Span绘制不完全等异常现象,就该问题进行处理。
虽然我发现包括,手Q、脉脉、网易云音乐等在这块处理都有问题,或者是都没有处理吧。。。因此欣然的写了这个算法。抱着造福一方的心态开源。。
最终的解决是猛然回头发现android.text.TextUtils#ellipsize(...):CharSequence
已经很好的封装了类似的功能。
还是没有明白解决啥问题?不多废话,上图!
简单如下:
mDemoTv.setText(SpanEllipsizeEndHelper.matchMaxWidth(demoSS, mDemoTv));
Copyright (c) 2015 LingoChamp Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.